JavaScript
  Home arrow JavaScript arrow Page 4 - Using the EXT JS Date Picker Widget
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Using the EXT JS Date Picker Widget
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2008-07-14

    Table of Contents:
  • Using the EXT JS Date Picker Widget
  • Invoking the Date Picker
  • Finishing the Example
  • Finishing continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using the EXT JS Date Picker Widget - Finishing continued


    (Page 4 of 4 )

    We can add a listener for this event very easily by specifying it in the configuration object passed to the date picker constructor. Change the constructor so that it appears as follows (new code is again shown in bold):

    //create the date picker

    var myDP = new Ext.DatePicker(

    {

    startDay: 1,

    listeners: {

    'select':selectHandler

    }

    }

    );

    The listeners property accepts an object literal listing the event to listen for as a property key and the handler function as the property value. Try the code out now; it should do everything that we set out to achieve. For reference, the complete file should now appear as follows:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

    <html>

    <head>

    <link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css">

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <title>EXT JS Datepicker Example</title>

    </head>

    <body>

    <label>Enter a date: </label><input type="text" id="dateField"><button id="openCalendar">Open Calendar</button><div id="calendar"></div>

    <script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>

    <script type="text/javascript" src="ext/ext-all.js"></script>

    <script type="text/javascript">

     

    //set local blank image

    Ext.BLANK_IMAGE_URL = 'ext/resources/images/default/s.gif';

     

    //define function to be executed when page loaded

    Ext.onReady(function() {

     

    //define select handler

    var selectHandler = function(myDP, date) {

     

    //get the text field

    var field = document.getElementById('dateField');

     

    //add the selected date to the field

    field.value = date.format('d/m/Y');

     

    //hide the date picker

    myDP.hide();

     

    };

     

    //create the date picker

    var myDP = new Ext.DatePicker(

    {

    startDay: 1,

    listeners: {

    'select':selectHandler

    }

    }

    );

     

    //render the date picker

    myDP.render('calendar');

     

    //hide date picker straight away

    myDP.hide();

     

    //define click handler

    var clickHandler = function() {

     

    //show the date picker

    myDP.show();

     

    };

     

    //add listener for button click

    Ext.EventManager.on('openCalendar', 'click', clickHandler);

     

    });

    </script>

    </body>

    </html>

    Summary

    Using the widgets and other classes provided by EXT JS is easy and intuitive, and can help you to quickly and easily create robust and attractive interfaces. The widgets are styled to a professional degree and work exactly as the API describes.

    -DOWNLOAD SOURCE-


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · I hope this article shows you how powerful Ext-js is and how easy it is to...
       · Dan.. great example. Since many pages have multiple dates/calendars, perhaps you can...
       · found this clean solution at: http://extjs.com/forum/showthread.php?t=20776
     

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT