My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
DatePicker  

#Documentation for the DatePicker class.

Introduction

The DatePicker object is instantiated, tied to a form text input, such that clicking in the input will bring up a calendar widget for picking dates.

The constructer takes an associative array of configuration parameters. The one required parameter is "relative", which is a string containing the id of the input field to bind to.

<input type="text" name="mydate" id="mydate_id" />
<script type="text/javascript">
var dpicker = new DatePicker({
 relative : 'mydate_id'
});
</script>

Parameters

The full list of available configuration parameters is as follows:

  • relative required - string containing the id of the form input to bind to
  • language optional (default 'en') - two-letter language code (currently supporting 'en', 'fr', 'sp', 'it', 'pt', 'de', 'nl', 'hu', 'ro', 'lt', 'lv', 'sv', 'dk', 'no', 'fi', 'ja', and 'zh')
  • zindex optional (default 1) - CSS zindex to use for the popup calendar
  • keepFieldEmpty optional (default false) - whether or not to keep the field empty when closing the calendar without picking a date. When false, it will use today's date to fill in an empty field.
  • clickCallback optional - a function with no parameters that is called when the input field is clicked.
  • cellCallback optional - a function with no parameters that is called when a calendar date is picked.
  • leftOffset optional (default 0) - number of pixels to shift the left of the popup calendar right.
  • topOffset optional (default 30) - number of pixels to shift the top of the popup calendar down.
  • relativePosition optional (default true) - whether or not we are positioning relative to the input itself, or relative to its containing positioned element.
  • showEffect optional (default "appear") - Scriptaculous effect to use when the popup is shown.
  • enableShowEffect optional (default true) - whether or not showEffect is used.
  • showDuration optional (default 0.2) - the duration for the showEffect.
  • closeEffect optional (default "fade") - Scriptaculous effect to use when the popup is closed.
  • enableCloseEffect optional (default true) - whether or not closeEffect is used.
  • closeEffectDuration optional (default 0.2) - the duration for the closeEffect.
  • afterClose optional - function to be called after the popup closes.
  • externalControl optional - a string holding the id of another element to bind an onclick listener to for opening and closing the popup calendar.
  • dateFormat optional - manual control of the date format, requires an array of two elements, the first itself being an array of three elements indicating how to order "dd" "mm" and "yyyy", and the second element being the character to use to separate the three date parts. For example, standard ANSI/ISO format would be [ ["yyyy","mm","dd"], "-" ]. If this is not specified, a default will be chosen based on the language setting.
  • setPositionTop optional (default 0) - if relativePosition is false, this is used as the CSS top attribute of the popup.
  • setPositionLeft optional (default 0) - if relativePosition is false, this is used as the CSS left attribute of the popup.
  • enableCloseOnBlur optional (default false) - causes the datepicker to close when the form input loses focus.
  • dateFilter optional - a DatePickerFilter object that specifies what months and dates to exclude from the datepicker.

Deprecated

Still supported somewhat for backwards compatibility, though defaults are no longer the same:

  • disablePastDate - when true, past dates are not selectable. Since the addition of dateFilter, setting this to true appends "DatePickerUtils.noDatesBefore(0)" to the existing date filter, if any.
  • disableFutureDate - when true, future dates are not selectable. Since the addition of dateFilter, setting this to true appends "DatePickerUtils.noDatesAfter(0)" to the existing date filter, if any. This takes place after the check on disablePastDate, so if for some reason you set both true, this one will be ignored.

Comment by holto...@gmail.com, Jun 8, 2009

I really like this cross-browser DatePicker. Thanks for your hard work.

Comment by analsand...@gmail.com, Jun 29, 2009

Thank you for this, just what I needed :D

Comment by igor.las...@gmail.com, Jul 27, 2009

hey guys why project is not available for downloading?!

Comment by alejandr...@gmail.com, Aug 31, 2009

Igor, maybe if you browse the source code you'll be able to download the widget.

Comment by csoti.at...@gmail.com, Oct 3, 2009

I couldn't find a fast rewind. If I have to go back in time 12 years is a little bot boring :) Help me guys, please.

Comment by benjamin...@gmail.com, Jan 6, 2010

this calander is monday to sunday cal, so i had to make a small tweek to the JS to make it a sun through saturday cal.

changed line 370 to 'en' : 'Sun','Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',

and changed line 766 to

var startIndex = d.getDay() % 7;

370 changes the label and 766 change the date numbers.

I am calling the calander with all defaut parameters and no filters.

Comment by Gowserle...@gmail.com, Jan 26, 2010

Some trouble with the first week and the current date.

If you change your computer date at '01/01/2010', this day not be highlighted because you forgot the class test at line 772.

A second problem with the current date. You forgot to test the current day (in this same control)

You need to keep your class test at line 772 (this is the new code) " / The first week / for ( var j = startIndex; j < 7; j++ ) {

a_d0?j? = {
d : daysIndex ,m : currentMonth ,y : currentYear ,b : badDatesdaysIndex? ,c : ( switchNextMonth )
? 'outbound' : (
((daysIndex == this.currentDay) &&
(currentMonth == this.todayDate.getMonth()) && (currentYear == this.todayDate.getFullYear())) ? 'today' : null)
}; daysIndex++;
}"

I change the class test again at line 804 to keep the current day test : " / Now the remaining weeks /

var switchNextMonth = false; for ( var i = 1; i < 6; i++ ) {
for ( var j = 0; j < 7; j++ ) {
a_di?j? = {
d : daysIndex ,m : currentMonth ,y : currentYear ,c : ( switchNextMonth )
? 'outbound' : (
((daysIndex == this.currentDay) &&
(currentMonth == this.todayDate.getMonth()) && (currentYear == this.todayDate.getFullYear())) ? 'today' : null) ,b : switchNextMonth || badDatesdaysIndex?
};
"

Regards (sorry for my language , i'm poor with english)

Comment by ljd...@gmail.com, Feb 2, 2010

please support also the onfocus event.. when the user uses the tab for migrating to other input boxes the calendar dont show as it only trigger the focus event not the click event.. i cant find a way for prototype to trigger the click event on focusing in the certain input boxes.. so a fix would be to modify the code.. but unfortunately im not that good on scripting javascript so maybe if someone got to the same problem and manage to fix it, it would be a great help.. tnx for the great script

Comment by 99mi...@gmail.com, Feb 10, 2010

Awesome work! Is there a way to just embed the calendar into a page? I don't want it to pop up in a form, I want to embedded in the page. Thanks!

Comment by stende...@gmail.com, Mar 2, 2010

This is super cool - very functional! My problem is, that I really really want to replace the old CalendarXP with someting more contemporaty like this, but I need to have date-range functionality. That is - for instance - if the user select April 2nd in the first box, they will not be able to select a date prior to April 2nd in the second box. I assume I can call the afterClose function, check for the value of the first date and do something, but I assume the second box would already be initialized by then, right? Any ideas?

Comment by toby%tob...@gtempaccount.com, Mar 3, 2010

Neat!

Comment by alexjasc...@gmail.com, Jul 14, 2010

Very nice.

However I would like to see it being able to take a standard dateformat - i.e. 'yyyy-MMM-dd'/'yyyy-mm-dd'/etc instead of that ugly array.

Comment by alexjasc...@gmail.com, Jul 16, 2010

For anyone else using this, dont be caught out calling the parameter 'zIndex' with a capital I. It has to be 'zindex' - all lowercase.

Comment by acolesni...@gmail.com, Aug 14, 2010

Seems does not working in FireFox? 3.6.8 (works OK in Google Chrome)


Sign in to add a comment
Powered by Google Project Hosting