Home arrow JavaScript arrow Page 4 - Using the EXT JS Date Picker Widget
JAVASCRIPT

Using the EXT JS Date Picker Widget


In a recent article I looked at the EXT JS JavaScript library and gave a brief overview of what it does and what it contains. In this article we’re going to look at implementing one of the many widgets that come with the library – the date picker widget.

Author Info:
By: Dan Wellman
Rating: 5 stars5 stars5 stars5 stars5 stars / 17
July 14, 2008
TABLE OF CONTENTS:
  1. · Using the EXT JS Date Picker Widget
  2. · Invoking the Date Picker
  3. · Finishing the Example
  4. · Finishing continued

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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.

blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials