MooTools DatePicker
Will work for any date-format and even supports time-picking.
4 skins ready for download, and it's easy to skin it yourself.
(I just tried to create the best javascript datepicker available)
License
You can freely use this work - but some rights are reserved.Downloads
» Source code (for development)
Additional downloads
» Basic Skin - CSS only» Vista Skin - CSS & Images
» OSX Dashboard Skin - CSS & Images
» jQuery UI Skin - CSS & Images
Try the examples at the bottom of this page to check out the different skins!
MooTools Forge version
There is a fork of this project that's been included in the MooTools Forge. It fixes many smaller issues, and hooks into MooTools' own Date object. Check it out.GitHub
I am using a Git repository for code management. Feel free to contribute.Requirements
Requires MooTools Core v1.2+Tested on Firefox 3 (OSX, Win XP, Win Vista), Safari 3 (OSX, Win XP), Safari 4 beta (OSX), IE 7 (Win XP, Win Vista), IE 8 (Vista) and even IE6 (XP @ VirtualPC). Please help extend this list.
Usage
new DatePicker(input-target-selector [, options-object]);where the input-target-selector naturally is a MooTools selector (eg. .datepickers or #great_picker). The datepicker will be effective for all selected input elements. Usage examples are given at the bottom of this document.
Usage with Ajax
When loading content by Ajax after creating the DatePicker instance, simply re-scan the DatePicker targets by calling attach(), for example:my_datepicker.attach();
Using the Skins
Just include the CSS file of a skin, and specify the datepicker class (pickerClass) through your datepicker options. I recommend putting all skin files in one subfolder on your filesystem. Since image-locations are stored as relative paths in CSS, the images will work out of the box.Options
| Option | Default value | Description |
|---|---|---|
| pickerClass | datepicker | CSS class for the main datepicker container element. |
| toggleElements | null | Toggle your datepicker by clicking another element. Specify as a MooTools selector. The resulting elements are mapped to the selected datepickers by index (the 1st toggle works for the 1st input, the 2nd toggle works for the 2nd input, etc.) |
| days | ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] | Labels for the days, allows for localization. |
| dayShort | 2 | Length of day-abbreviations used in the datepicker. |
| months | ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] | Labels for the months, allows for localization. |
| monthShort | 3 | Length of month-abbreviations used in the datepicker. |
| startDay | 1 | First day of a week. Can be 0 (Sunday) through 6 (Saturday) - be aware that this may affect your layout, since days in the last column will likely have a style with right-margin: 0px;which would need to be applied to a different day. Default value 1 is Monday. |
| timePicker | false | Enable/disable timepicker functionality. See timepicker example below. Hours/Minutes values can be changed using the scrollwheel. |
| timePickerOnly | false | (v1.16+) set to true to use datepicker for time-selection only; recommended formatis H:i; will automatically force timePicker and startView options into timepicker mode |
| yearPicker | true | Enable/disable yearpicker functionality. Makes it much easier to change years. |
| yearsPerPage | 20 | Amount of years to show in the year-picking view. Be aware that this may affect your layout. |
| format | d-m-Y | Visible date format. Does not affect the actual output when your form is submitted (refer to the inputOutputFormat for that). Supported format symbols are described in the "Dateformatting" section. |
| inputOutputFormat | U | Define how the input value of the original datepicker input element is interpreted. After selecting a date, it's value will be again formatted in this format. Refer to the "input/output format" example. The default value U is a Unix-timestamp. Supported format symbols are described in the "Dateformatting" section. For example: to use MySQL dates 1-on-1 simply set Y/m/d. If you encounter problems with your formatting, try enabling the debug option, it will alert date-parsing errors. |
| animationDuration | 400 | Duration of the slide/fade animations in milliseconds. |
| useFadeInOut | true (false on Internet Explorer) | Whether to fade-in/out the datepicker popup. |
| startView | month | Initial view of the datepicker. Allowed values are: time(only when timePicker option is true), month,year, decades |
| allowEmpty | false | When set to true the datepicker intializes empty when no value was set (instead of starting at today). In addition the backspace- and delete-key will remove a value from the input. Check out the Allow empty example below. |
| positionOffset | { x: 0, y: 0 } | Allows you to tweak the position at which the datepicker appears, relative to the input element. Formatted as an object with x and y properties. Values can be negative. |
| minDate | null | Minimum date allowed to pick. Blocks anything before. Formatted as an object with a date and format property, which allows specification in any format you want. Example: { date: '10-03-2009', format: 'd-m-Y' } or { date: '2009/11/28', format: 'Y/m/d' } |
| maxDate | null | Maximum date allowed to pick. See minDate. |
| debug | false | When enabled, will not hide the original input element. Additionally, any formatting errors will be alerted to the user. |
| onShow | $empty | Event hook triggered when the datepicker pops up. |
| onClose | $empty | Event hook triggered after the datepicker is closed (destroyed). |
| onSelect | $empty | Event hook triggered when a date is selected. (v1.16+: comes with 1 argument, a standard javascript Date object representing the selected Date) |
Requested/planned features
- Support for date-range picking
- Prepare for MooTools 1.3 (2.0?) (personal todo)
Date-formatting
The date-formatting functions featured in the DatePicker support basic PHP date-format syntax. Supported symbols are listed below. Unsupported symbols will just be output as provided. To use the supported symbols literally, escape them with a \.
- y - Two digit representation of a year
- Y - Four digit representation of a year
- m - Numeric representation of a month, with leading zeros
- n - Numeric representation of a month, without leading zeros
- M - A short textual representation of a month, three letters
- F - A full textual representation of a month, such as January or March
- d - Day of the month, 2 digits with leading zeros
- j - Day of the month without leading zeros
- D - A textual representation of a day, three letters
- l - A full textual representation of the day of the week
- G - 24-hour format of an hour without leading zeros
- H - 24-hour format of an hour with leading zeros
- g - 12-hour format of an hour without leading zeros
- h - 12-hour format of an hour with leading zeros
- a - Lowercase Ante meridiem and Post meridiem
- A - Uppercase Ante meridiem and Post meridiem
- i - Minutes with leading zeros
- s - Seconds, with leading zeros
- U - Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
Creating your own skin
The Datepicker generates very clean XHTML, with many class-hooks for CSS. Refer to the existing skins for a speed-start. Some notes:- The previous, next and close elements have textual contents («, », x) by default; as done in the additional skins, these can be hidden using (for example) text-indent: -999px style
- The body element has 1 unclassed child, which in turn has 2 unclassed children. These are used for animation, and should be ignored. Their styles are based on the body class and should have no influence on the rendering of your datepicker. Just imagine the body element directly contains either the years, months, days or time class.
- The class selected is added to the date/month/year representing the current value.
- The class unavailable is added to any date/month/year which is outside the configured range (using the minDate and maxDate options).
- Every day element also has a day0 ... day6 class added, indicating which day of the week it is (0 being Sunday through 6 being Saturday).
- Every week element also has a week0 ... week5 class added, indicating which row of weeks it is (there is always 6 weeks displayed).
- Every month element also has a month1 ... month12 class added, indicating which month of the year it is.
- Every year element also has a yearX class added, where X simply is the index of the displayed year (0 being the first year).
Examples
Skins
Some basic examples, showing the use of different skins.» view code
Javascript
window.addEvent('load', function() {
new DatePicker('.demo_vista', { pickerClass: 'datepicker_vista' });
new DatePicker('.demo_dashboard', { pickerClass: 'datepicker_dashboard' });
new DatePicker('.demo_jqui', { pickerClass: 'datepicker_jqui', positionOffset: { x: 0, y: 5 } });
new DatePicker('.demo', { positionOffset: { x: 0, y: 5 }});
});HTML
<label>Datepicker with Vista skin:</label> <input name='date_B' type='text' value='' class='date demo_vista' /> <label>Datepicker with OSX Dashboard skin:</label> <input name='date_B' type='text' value='' class='date demo_dashboard' /> <label>Datepicker with jQuery UI skin:</label> <input name='date_B' type='text' value='' class='date demo_jqui' /> <label>Datepicker basic (CSS only):</label> <input name='date_B' type='text' value='' class='date demo' />
CSS
input.date {
width: 150px;
color: #000;
}Yearpicking / Timepicking
Two examples that show how you can enable or disable yearpicking and timepicking.» view code
Javascript
window.addEvent('load', function() {
new DatePicker('.demo_noyear', { pickerClass: 'datepicker_vista', yearPicker: false });
new DatePicker('.demo_time', { pickerClass: 'datepicker_vista', timePicker: true, format: 'd-m-Y @ H:i' });
});HTML
<label>Datepicker without yearpicker:</label> <input name='date_B' type='text' value='' class='date demo_noyear' /> <label>Datepicker with timepicker (use mousewheel to change time):</label> <input name='date_B' type='text' value='' class='date demo_time' />
Allow empty
Allowing no value by setting the allowEmpty option to true. Press backspace or delete to clear the selected date again.» view code
Javascript
window.addEvent('load', function() {
new DatePicker('.demo_allow_empty', {
pickerClass: 'datepicker_dashboard',
allowEmpty: true
});
});HTML
<label>Datepicker starting at and allowing no value:</label> <input name='date_allow_empty' type='text' value='' class='date demo_allow_empty' />
Toggle by Element
Toggle the DatePicker through a separate element. Click the calendar icon.
» view code
Javascript
window.addEvent('load', function() {
new DatePicker('.date_toggled', {
pickerClass: 'datepicker_dashboard',
allowEmpty: true,
toggleElements: '.date_toggler'
});
});HTML
<input name='date_toggled' type='text' value='' class='date date_toggled' style='display: inline' /> <img src='img/calendar.gif' class='date_toggler' style='position: relative; top: 3px; margin-left: 4px;' />
Restricted date-range
An example showing how you can restrict the input range of dates.
» view code
Javascript
window.addEvent('load', function() {
new DatePicker('.demo_ranged', {
pickerClass: 'datepicker_vista',
inputOutputFormat: 'd-m-Y',
yearPicker: false,
minDate: { date: '10-03-2009', format: 'd-m-Y' },
maxDate: { date: '25-06-2009', format: 'd-m-Y' }
});
});HTML
<label>Datepicker restricted to dates between 10-03-2009 and 25-06-2009:</label> <input name='date_B' type='text' value='20-03-2009' class='date demo_ranged' />
Starting value (input/output value)
These examples show how you can set the starting value by simply putting it in your original value tag. Additionally, you may use the option inputOutputFormat to specify how to interpret this value, and how it will be output again after picking a date.
Please note: The debug option is enabled which will show you the original input and its actual value (the first input element), which is normally hidden. The second input element is the datepicker.
» view code
Javascript
window.addEvent('load', function() {
new DatePicker('.demo_value', {
pickerClass: 'datepicker_jqui',
debug: true
});
new DatePicker('.demo_value2', {
pickerClass: 'datepicker_jqui',
inputOutputFormat: 'Y/m/d',
debug: true
});
});
HTML
<label>Datepicker starting at Unix-timestamp 1234567890 (14th of Februari 2009):</label> <input name='date_B' type='text' value='1234567890' class='date demo_value' /> <label>Datepicker starting at 2009/06/24 (to read as 'Y/m/d'):</label> <input name='date_B' type='text' value='2009/06/24' class='date demo_value2' />
Localized Month/Day labels
This example shows how simple it is to change the month/day labels in another language.
» view code
Javascript
window.addEvent('load', function() {
new DatePicker('.demo_dutch', {
pickerClass: 'datepicker_dashboard',
days: ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'],
months: ['Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'October', 'November', 'December']
});
});HTML
<label>Datepicker with Dutch labels:</label> <input name='date_B' type='text' value='' class='date demo_dutch' />



Comments (291)
I tried to get the DatePicker running with FormCheck, but was not successfull. Standalone (without your code) FormCheck worked, but with your DatePicker, FormCheck didn't work anymore.
I tracked this down to FormCheck also doing validation on the original input field (even though set to "display: none"). I fixed this by modifying FormCheck not to validate elements that are "display: none".
--
Martin
Second time I have needed a datepicker and timepicker in one. Thank you very much.
Is there a way to set the value of the field to a specific timestamp? so if I check a check box somewhere:
var picker = new DatePicker('.demo_vista', { pickerClass: 'datepicker_vista', timePicker: true, format: 'Y-m-d H:i:s' });
//var started is the checkbox;
started.addEvent('change', function() {
usertime.set('value', '1242763047');
});
Great documentation too.
Maybe in the future ? :-)
Is there a way to set the date via javascript? I tried the DatePicker.select method, but this doesn't work if the date input hasn't had focus. The onFocus event sets the this.input and this.vsiual properties which are used in the select method.
var val ='2009-07-05' ;
var formatted_val =cal.format (
new Date (cal.unformat (val, cal.options.inputOutputFormat)),
cal.options.format
) ;
$('myinput').value =val ;
$('myinput').getNext ().value =formatted_val ;
Hope that helps,
I used a similar workaround, but the getNext() increases the coupling with the DOM. If the position of the sibling element in the DOM changes somehow (which is not unthinkable imho) you're screwed. I was really looking for a somewhat more elegant solutions, but couldn't found one without some serious refactoring of the DatePicker class.
onShow: function() {
if (Browser.Engine.trident4) $$('select').setStyle('visibility', 'hidden');
}
onClose: function() {
if (Browser.Engine.trident4) $$('select').setStyle('visibility', '');
}
I consider making this part of the official release. Any thoughts?
Right, that seems good, I just worry about the users being frightened that the inputs are disappearing. I ended up just moving it to the right which will do for now. Mostly, I will try to convince them to upgrade their browser.
I think you could add it in to the next release, but as an option not as a default.
Thanks so much for your help,
Matt
datepicker = new DatePicker(".datefield",{ pickerClass: 'datepicker_vista', startDay: 0,
onShow:function(){
datepicker.IframeShim = new IframeShim(datepicker.picker).show();
},onClose:function(){
datepicker.IframeShim.destroy();
}
});
A Calendar I'd so much like to match with mootools is here:
http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/html/rich_calendar.html
I'd like to add this functionality if you are too busy?
By the way: I wasn't suggesting matching the whole functionality of the jBoss date picker in my previous posting; simply the week number).
so, if I have two of them, I could hook them together so dateA is always before dateB
thanks for sharing this, it's one of the best pickers I've tried (and I've tried LOTS)
Excelent script! Works like a charm.
I've been trying to set te minDate propertie of an input acording to the selected date of another. For example, to pick the check in and check out dates of a hotel. For example, if I pick 2009-08-08 for the check in, automatically set that date as the minDate for the checkOut (maybe, plus X days).
I've been trying with the onShow or onClose events, but I can't make it works. Could you help me?
Thanks in advance :)
Do you have any RSS thread (Datepicker only) which we can link to, to get latest update as soon as there is one ?
Also, do you have any change log to see improvements from one version to an other ?
Some ideas of improvements:
-Possibility to place it in line (always shown).
-Possibility to drag it.
I'd like to add this :
It would be great to allow one to change the minDate dynamically. I use 2 datepicker (start date and end date). When i select the start date, i'd like the end date to auto ajust to the start date AND the datepicker not to allow dates before the start date.
Hope you understand. I guess i could do it by recreating an instance of DatePicker onSelect of the first one.
Again, thanks for this tool!
Thanks
Is it possible to have the calendar inline (always displayed) above the input element?
Is it possible to start the calendar in decades mode, then month, then date?
If anyone could answer this question, or build a calendar that can ;) I would greatly appreciate it!
17.5kb as minified really doesn't justify its use for me though. Possible just needs a different way to compress it? I tried bananascript dot com and got it down to 6kb. You might want to dish that out as the minified versin with an explanation of what charset to use on the script include :))
something like :
var picker = new DatePicker(myElement,{....});
How can i empty the box after declaration with javascript?
How can i take the value of input box with javascript to control?
Some ideas (sent by mail + 1 new) :
-(new !) Add the possibility to show week numbers on each week line.
-Auto-date update two datepickers according to the value of one-another :
on minDate update, if stopdate's currently selected date < minDate then stopedate's currently selected date = minDate.
Same for max date
on maxDate update, if stopdate's currently selected date > maxDate then stopedate's currently selected date = maxDate.
Some problems i encoutered :
-When i configured mindate with current time. Current day wasn't selectable. I had to clearTime() so that current day would be selectable.
-My "value input" START_DATE was empty after creating the DatePicker. It would be great that upon creation of a datepicker on an input (here, what i call the "value input"), IF that input is empty then either the date input is also empty or the value input is filled with the date input value. Maybe this could be set up using options ?
-I tried to access $$('input[name=START_DATE]').retrieve('datepicker'). That was unsuccessful. Is it normal ? do i have to do something particular ? I thought it was logical that the datepicker would be attached to the input by default.
-Make it possible to specify minDate: 'today'. I think this is something alot of people would use.
Always and forever : thanks for this tool !
Other than that, it's very nice.
var oDatePicker = new DatePicker(oDate,{
format: 'd-m-Y',
toggleElements: '#DateResume',
});
#DateResume is a SPAN containing the date.
oDate is an input[type=hidden]
1-The DatePicker doesn't auto-update the span, have to do it onSelect.
2-The DatePicker appears in the top left corner instead of under the SPAN (i suppose it's cause it can't find the input)
Thanks again
Also when the page loads the current date time shows, but the 'value' is empty if the form is submitted. So, how can I set the value and have the format correct? Hope this is clear.
Using in a script section called via body=onload():
---------------------------------------------------
mydatepicker = new DatePicker('.demo_time', { pickerClass: 'datepicker_vista', timePicker: true, format: 'd-m-Y @ H:i' });
And this in the form:
---------------------
<input name='mydate' type='text' value='$context{dt}' class='date demo_time' />
The html is built in a Perl script to show $context{dt} becomes initialized with a time that was previously submitted. That value would be something like: 1249544543 . Would also like to change this value with javascript and have the format correct.
Any thoughts? Thanks.
How can i empty the box after declaration with javascript?
How can i set and get the value of input box with javascript to control?
Take a look at the workaround Cyrille (05-07-2009, 16:57) described. It isn't a very elegant/safe solution, but as far as I know the only one available.
If your main input is invisible (display none or type hidden) the picker won't appear in IE7 and will be displayed at the top left corner in FF 3.5
To solved this i changed the code like that:
line 148
- this.onFocus(item, clone);
+ this.onFocus(item, clone, togglers[index]);
line 177-178
- onFocus: function(original_input, visual_input) {
- var init_visual_date, d = visual_input.getCoordinates();
+ onFocus: function(original_input, visual_input) {
+ var init_visual_date, d = ($defined(toggler) ? toggler:visual_input).getCoordinates();
Hope this helps
line 177
- onFocus: function(original_input, visual_input) {
+ onFocus: function(original_input, visual_input, toggler) {
sry for the 2nd post
// this will change the value of the form field
// but will not update the display
form.datefield.value=1249621200;
I need a way to update the value and display of a date field.
my_datepicker.attach();
to attach the datepicker in the ajax form so that it will work?
i have 2 questions: i'm trying to set the date and time for an update form. i've set the value of my textbox field to:
value='27/08/2009 @ 15:00'
and the format to:
format: 'd/m/Y @ H:i',
but when the page loads, the date sticks but the time updates to the system time of my machine!
the 2nd question is i like to disable the form fields (to restrict users typing incorrect dates and then having to validate them) but i'm a asp.net user meaning i can access the form field when the page is submitted...
i usually use a hidden field to store the values of disabled fields, but how do i pass the date/time value to this field?
any info you can provide would be awusm,
cheers,
jake
onSelect: function(d) {
$('hidden_field').value = d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":00";
}
but still cant get the form fields to load the time correctly? i've tried every format i can think off...
cheers,
jake
format: 'd/m/Y @ H:i'
and:
inputOutputFormat: 'd/m/Y @ H:i'
works a treat ;)
In case anybody needed this, I am using the script on an input with a label related to its id, so i modified it a bit to assign the id to the clone and remove it from the original input. Starting line 130 of the uncompressed script.
var display = item.getStyle('display');
var originalID = item.getProperty('id');
var clone = item
.setStyle('display', this.options.debug ? display : 'none')
.store('datepicker', true) // to prevent double attachment...
.removeProperty('id')
.clone()
.store('datepicker', true) // ...even for the clone (!)
.removeProperty('name') // secure clean (form)submission
.setProperty('id', originalID)
.setStyle('display', display)
.set('value', init_clone_val)
.inject(item, 'after');
Cheers!
window.addEvent('load', function() {
new DatePicker('.demo_vista', { pickerClass: 'datepicker_vista',inputOutputFormat: 'm/d/Y',debug: true });
});
Filed input must be m/d/Y and it must display like that and write to the database like that. But while it writes to the database ok...and displays ok...the hidden field ALWAYS displays the wrong date...it jumps ahead one month? So if I input 09/03/2009 the hidden field will display 03-10-2009 and have that date selected on the pop up calendar? How do I make it pick the right date?
Anyway...I think Jake was onto something....with
onSelect: function(d) {
$('hidden_field').value = d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":00";
}
But being a javascript weakling...I don't know how to implement it or adapt it?
Anyone help?
If you start with the date 08/31/2009 and click on the calendar then click the right arrow to go to the next month it goes to October instead of September!
Can this be fixed?
May I suggest you add the following to the CSS so the Picker layout won't be affected by any existing CSS:
.datepicker .header {
margin: 0;
padding: 0;
background: none;
[...]
}
In my case I had already a .header class with some margin, padding and background set which led to layout problems in the Picker.
Cheers.
we made a keyboard navigable version of this script :
http://www.fri-dev.com/index.php?post/2009/09/04/Monkey-Physics-datepicker-%3A-keyboard-navigation-fix
Iam not sure if this is bug or something Iam doing is wrong
Can i make offer for you datepicker: when i attach image for toggle calendar way text field lost action on Focus event for show calendar instance? It mast be work too.
they click very often at the arrows ...
It is sadly a killer argument in much projects :(
May you change the number of the year and month with a select-box and if the time-picker is enabled you add the timepicker (smaller) at top of the chooser instead of adding the second step.
Grettings from Germany
}.bind(this));
On the new line 174, add
//save reference to clone for later use
this.clone = clone;
Then add the following code after
}.bind(this));
},
(so on line 178 that is)
refresh: function(){
$$(this.attachTo).each(function(item) {
// determine starting value(s)
if ($chk(item.get('value'))) {
var init_clone_val = this.format(new Date(this.unformat(item.get('value'), this.options.inputOutputFormat)), this.options.format);
} else if (!this.options.allowEmpty) {
var init_clone_val = this.format(new Date(), this.options.format);
} else {
var init_clone_val = '';
}
this.clone.set('value', init_clone_val);
}.bind(this))
},
Now you can set the new UNIX timestamp in your own input/select, and call the refresh function of the DatePicker.
I'm using your CSS based date picker. I'm using CSS with basic skin. but I see some special characters («) for previous and next buttons.
Also the width of the title (month year, next button, close button) doesn't extend fully.
Also i see some blank space between border and calendar. I'm using IE7. When i run the demo from this website it works fine. But when I refer to downloaded files datepicker.js and above CSS...it is little off..
Have the InvalidWeekDays implemented??? or setDisabledWeekDays, this i found in CalendaPopup.JS, is very usefull.http://www.mattkruse.com/javascript/calendarpopup/index.html
I almost have it working but encountered what I think is a bug. My inputOutputFormat is "n/j/y". If the date that is passed in looks like "9/12/09", datetimepicker.js will throw an error that it cannot format the year. I believe this is because your regex matches the "1" in "12", and therefore thinks the chunk to match against "y" is "/09" rather than "09".
My temporary workaround is to reverse the order of the regex like "3[01]|[12][0-9]|[1-9]" instead of "[1-9]|3[01]|[12][0-9]" so that it picks the biggest match first.
Not sure if this is the best solution, but thought you might want to know about a possible bug.
Otherwise, great job and thanks for the tool!
Thanks for the great tool!!
We are using the datepicker in our .net 3.5 website project there is a need to disable some of the dates on the calendar depending on the selection in a dropdownlist server control.
I have never worked with mootools
Please help!!!
how can i set the current date into the input box onshow
my workaround (it is very dirty^^):
datepicker.visual.set('value', datepicker.format(datepicker.d, datepicker.options.inputOutputFormat));
is there a more simply way?
i can't change the input-field-value from outside after it is bind on datepicker
example $('id_input_field').value='';
When I set a Datepicker in the page, the visible value in the text field is right (today's date). But if I submit the form that has the Datepicker in it, without changing the default values, the form field comes out blank? If I change the value, everything gets submitted the right way.
Any suggestions?
In FF3.5/Opera 10 works like a charm
var cal = $$('.datepicker_vista')[0];
var screenHeight = window.getSize().y;
var screenBottom = window.getScroll().y+screenHeight;
var calendarHeight = cal.getSize().y;
var calendarBottom = cal.getPosition().y+calendarHeight;
if(calendarBottom>screenBottom){
var newY = calendarBottom+10-screenHeight;
window.scrollTo(0,newY);
}
Also, for birthday pickers, it's nice to hide the year in the title. So I added an option for that:
if(this.options.hideYear){
this.picker.getElement('.titleText').set('text',this.options.months[month]);
}else{
this.picker.getElement('.titleText').set('text',this.options.months[month]+' '+this.d.getFullYear());
}
And last, although your documentation and your example show minDate and maxDate to be inclusive, when I try it on my own page it's exclusive. Any thoughts offhand? I can send you the code if you want to pm me. The page isn't live yet.
Thanks,
Bob
Hi there!
VERY nice Datepicker - best i've ever seen and i wanted to include it into my (under development) CSS-Frame Layout you can find over at http://www.artness.de/area/.
Two "Bugs" i am fighting with are:
In IE the Datepicker will "hide" all DIVs and display only itself. All Div's reveal again if the datepicker ist closed.
To workaround this strange behaviour, i needed to inject() it inside the DIV where the toggler (input field) is placed.
The 2nd Problem is, that the screen position is calculated absolutely + scrolled offset.
The DIV the datepicker toggler is located in, is scrollable so the screen itself stay where it is but the div with the toggler scrolls. The result is, that the datepicker will not display right below the toggler but somewhere else.
Is there any chance of a workaround or a fix .. like some extra option to setup the target the picker should be injected to:
options: { injectTarget : false }
this.picker = new Element('div', { 'class': this.options.pickerClass }).inject(this.options.injectTarget ? this.options.injectTarget : document.body);
and 2ndly to have an option on how to place the datepicker - if the whole page is scrolled, everything is fine but if a scrollable div is scrolled, the repositioning fails ...
sorry for my english - it's not my mother tongue though.
Keep up the excellent work
my date still formatted (05-10-2009) in the input text..
my setting:
<pre>
inputOutputFormat: 'd/m/Y',
</pre>
and html
<code>
<input size="30" value="05/10/2009" class="date date_pick" type="text"></code>
i hve set the value is current date..
please help.. thanks
setMinDate: function(smindate, sformat) {
this.options.minDate = this.unformat(smindate, sformat);
this.options.minDate.setHours(0);
this.options.minDate.setMinutes(0);
this.options.minDate.setSeconds(0);
this.options.minDate.setMilliseconds(0);
}
Also i would suggest initializing the minDate's hour, minute and seconds and even milliSeconds, so that date comparisons will be more accurate.
So the "formatMinMaxDates" function should be:
formatMinMaxDates: function() {
if (this.options.minDate && this.options.minDate.format) {
this.options.minDate = this.unformat(this.options.minDate.date, this.options.minDate.format);
this.options.minDate.setHours(0);
this.options.minDate.setMinutes(0);
this.options.minDate.setSeconds(0);
this.options.minDate.setMilliseconds(0);
}
if (this.options.maxDate && this.options.maxDate.format) {
this.options.maxDate = this.unformat(this.options.maxDate.date, this.options.maxDate.format);
this.options.maxDate.setHours(23);
this.options.maxDate.setMinutes(59);
this.options.maxDate.setSeconds(59);
this.options.maxDate.setMilliseconds(999);
}
}
Anyways, good work on this datepicker, works very well ! Thanks.
-Emil
This app looks great!!! I'm looking to replace my current date picker, I'd love to use this one but I was wondering whether its easily possible to separate the output in to 3 inputs/selects this is essential for the app its going into.
If its not possible I will look at writing the functionality into the datepicker if thats ok?
Please let me know!
Vince
Great components but it lacks the functionality to alter the value remotely via javascript...
I took the liberty and fixed this problem with the following solution:
I define an additional event for the original input element inside the attach() function of the class. (In my version of the script - which is 1.16 - this is line 143):
item.addEvent(\'change\', function(value) {
this.input = item;
this.visual = clone;
var d = new Date(this.unformat(value, this.options.inputOutputFormat));
this.select({ day: d.getDate(), month: d.getMonth(), year: d.getFullYear() });
}.bind(this));
After this you can change the value of the element by firing the change event, e.g.
$(\'mydatepicker\').fireEvent(\'change\', \'2009-10-23\');
Please make sure to set the inputOutputFormat property according to your date format!
Cheers and thanks for the component!
Pepe / Developer at www.groupion.com
The only thing I'd like to see implemented, is the option "zIndex": if you're using the picker in a modal window, it will be displayed behind it. It's just 1-2 lines of code to modify, I've did it to my copy and thought I'd share the idea.
Thanks again!
inputOutputFormat: \'Y/m/d\'
It\'s a really great little tool, Thank you.
I'd like to know if this script allow us to open the calendar directly when the mouse is over the form field ?
i don't want the users to have to click in the form field to open the calendar.
Can you tell me if it is possible ?
Thanks
Olivier
My input/output format is "Y-m-d", my display format is "F j, Y".
Dates in September, like "2009-09-17" are being formatted as "October 17, 2009", not "September 17, 2009".
I haven't figured out why. Seems to be happening only with dates September. All my September dates are being rendered as October.
But then if I use the datepicker to change the date, September is fine. This is only happening when the datepicker is initialized. It makes no sense.
No wonder it wasn't noticed before -- It will only happen on days like today (Oct 31) when you are initializing to a month which doesn't have this date (eg September 31, which doesn't exist).
line 711 in the "unformat" method, this line fails:
case 'n': d.setMonth(v - 1); break;
I can't change the date to September, because the current date is October 31 and there is no September 31. The method fails silently, and I end up with the wrong month.
To fix this, just add this before the "switch" on line 707:
d.setDate(1);
For general consumption, you might want more sophisticated logic, but that fixed my problem.
Cheers
- Make it work well with OverText (There are a few issues, which I suspect is due to the cloning of elements)
- Have it implement Events, and fire onShow / onClose events, rather than manually calling the functions (this allows multiple functions to be called onShow / onClose, and also allows adding of events nicely after the DatePicker object is created)
- Allow the picker to be manually shown and hidden externally (I know you can set a manual toggler on creation of the DatePicker, but this isn't very flexible)
- For ultimate customisation, instead of having manual "new Element("s everywhere, allow customization of the generated HTML. Maybe you could specify some sort of "default templates" and then populate these with generated data? (All I was personally after was changing the symbol for moving left and right in months, but the HTML template route seems like it could then handle practically every possible customization.)
- Add an option to add a \"Skip\" button to the time picker.
- When firing the event \"onClose\", pass along an object with details of the selected time: i.e. the time itself and whether \"Skip\" was pressed in the suggestion above
The reason the above would be useful is that for an events calendar, whether a time is needed may be event-dependent. Also: on selection of the date / time, there may have to be some code to deal with whether the user want to specify a time or not.
The div that contains the picker needs a z-index, i tried getting the calender to work on a page that had a background div and it took me some time to figure out why it wouldn't show.
Sure one could argue it's IE's fault, but it's a bug no matter how you put it, and can be easily mended if you use
Date.getFullYear().toString().substring(2);
Date.getYear() is obsolete, please don't use it. :)
One 'bug' or at least strange behavior. When I load the full moretools, the minDate and maxDate fields break functionality. Without those two, everything works fine.
I've just noticed something wrong (t.tostring()) in the unformat function and Mootools 1.2.4 when option mindate is set...
the refresh function by Rekcor is not free of bugs. The clone is saved in the main DatePicker-objekt, but you have to save it in the attachTo-Objects to get right results if you have more than one Date-Field.
So change :
this.clone = clone; => this.attachTo[index].clone = clone;
this.clone.set('value', init_clone_val); => item.clone.set('value', init_clone_val);
After implementing some stuff using Mootools more, our datepickers failed to work. I eventually tracked it down to a problem in formatMinMaxDates() - the date extentions has added a Date.format() function to native date objects, so the test to see whether this.options.minDate/maxDate was a Date always assumed it wasn't a date. - Lines 91 & 94. Here's the fix I put in place: Beginning at line 90: formatMinMaxDates: function() { if (this.options.minDate && $type(this.options.minDate) != 'date') { this.options.minDate = this.unformat(this.options.minDate.date, this.options.minDate.format); } if (this.options.maxDate && $type(this.options.maxDate) != 'date') { this.options.maxDate = this.unformat(this.options.maxDate.date, this.options.maxDate.format); this.options.maxDate.setHours(23); this.options.maxDate.setMinutes(59); this.options.maxDate.setSeconds(59); } } Best wishes, Craig
or cancel
After implementing some stuff using Mootools more, our datepickers failed to work.
I eventually tracked it down to a problem in formatMinMaxDates() - the date extentions has added a Date.format() function to native date objects, so the test to see whether this.options.minDate/maxDate was a Date always assumed it wasn't a date. - Lines 91 & 94.
Here's the fix I put in place:
Beginning at line 90:
formatMinMaxDates: function() {
if (this.options.minDate && $type(this.options.minDate) != 'date') {
this.options.minDate = this.unformat(this.options.minDate.date, this.options.minDate.format);
}
if (this.options.maxDate && $type(this.options.maxDate) != 'date') {
this.options.maxDate = this.unformat(this.options.maxDate.date, this.options.maxDate.format);
this.options.maxDate.setHours(23);
this.options.maxDate.setMinutes(59);
this.options.maxDate.setSeconds(59);
}
}
Hope this helps!
Craig
On line 625 we have:
# case 'y': f += (100 + t.getYear() + '').substring(1); break
It is returning 109 instead of 09
I replaced that with this to fix the problem:
# case 'y': f += (t.getFullYear() + '').substring(2); break;
Regards,
Ivan
Ihave one suggestion. It would be nice that you could type de date manually.
For some reason, the last row of dates doesn't show up. For example, in March 2009, the last visible row is 23-29 which means 30 and 31 aren't selectable. Your thoughts?
I fixed a glitch with the min/max month being one month off in renderYear.
Instead of "... +1 < ..:" and "... -1 > ..."
maybe "... <= ..." and "... >= ... + 1" is clearer.
I hope the pasting code works:
limited: function(type) {
var cs = $chk(this.options.minDate) && this.options.minDate;
var ce = $chk(this.options.maxDate) && this.options.maxDate;
if (!cs && !ce) return false;
var cc = this.d;
switch (type) {
case 'year':
return (cs && cc.getFullYear() < cs.getFullYear()) ||
(ce && cc.getFullYear() > ce.getFullYear());
case 'month':
return (cs && cc.getFullYear()*12+cc.getMonth()+1 < cs.getFullYear()*12+cs.getMonth()) ||
(ce && cc.getFullYear()*12+cc.getMonth()-1 > ce.getFullYear()*12+cs.getMonth());
case 'date':
return (cs && cc < cs) || (ce && cc > ce);
}
},
Playing with the CSS, I've found a simple workaround. I changed the height of the days. For whatever reason, IE renders them differently and there isn't enough space for the last row to show up on the fixed size background. Here's what worked for me (looks ok on other browsers - just a little extra space at the bottom):
.datepicker_dashboard .days .day {
float: left;
text-align: center;
overflow: hidden;
width: 23px;
padding-top: 1px;
height: 12px; /* Modified by Jeff Ropp to deal with IE6 */
margin: 0 1px 1px 0;
}
but i had problem with value of original input. when one doesn't select anything, the original input stays clear, so when the form with date submits, the value i got is not a default value, but null.
so i added some improvements to your attach function:
...
// determine starting value(s)
if ($chk(item.get('value'))) {
...
} else if (!this.options.allowEmpty) {
..
var init_orig_val = this.format(new Date(), this.options.inputOutputFormat); // init original control to default value
item.set('value', init_orig_val);
} else {
...
i think you can include something live this in feature releases
I also suggest that instead of using your own date parser and formater, use Date.Extras in Mootools.More. This way you can focus solving more usability issues as they arise.
-----------------------------------------------------
<head>
<script type="text/javascript" src="mootools-1.2.4-core-jm.js"></script>
<script type="text/javascript" src="datepicker.js"></script>
<link rel="stylesheet" type='text/css' href='datepicker.css'>
<script type="text/javascript">
window.addEvent('load', function() {
new DatePicker('.demo_ranged', {
pickerClass: 'datepicker',
inputOutputFormat: 'H:i',
timePicker: true,
timePickerOnly: true,
startView: 'time'
});
});
</script>
</head>
<body>
<input name='time' type='text' value='' class='date demo_ranged' /></body>
</html>
We also needed users to be able to manually enter their own dates and search on those, so we modified the addEvents on the clone as follows, which obviously enables user input and marries up entered changes with the hidden text box:
else {clone.addEvents({
'keydown': function(e) {
if (e.key == "tab") {
this.close(null,true); }}.bind(this),
'focus':function(e){ this.onFocus(item, clone);
}.bind(this),
'keyup':function(e){ this.input.set('value', this.visual.get('value')); }.bind(this)
}
thanks and best wishes
very nice work.
Is it possible to show specific start-day other than today or value in textbox??
Thanks
Alfred
I dont know if anyone could help me, but im completely stuck.
I have been dealing with this error for DAYS. And cant find a solution.
Every time a click a get the error: this.picker is null (line 36 of datepicker.js)
It has something to do with the usage of the jquery library im using for input validation scripts, because I just made a quick simple page where there is just the input for the datepicker, and it works fine. But when i import the jquery library it gives that error.
Using firefox/safari is not a big deal, because the website works OK, but using IE is not. You can not move the side bar of the browser and also the rest of javascript does not work as they do in other browser, because every time a click does not matter where, it gives the this.picker is null error. (On Safari it says: 'this.picker [null]' is not an object
I just hope there is someone that could help me, because im just going crazy....
Thank you!!!
Thanks
this is simply nice. But I am having trouble to get it work. Sorry I am real dummy in javascript, but this should not be so difficult to implement. I am getting following error when trying to copy code from examples
"DatePicker is not a constructor"
Could someone advice pleaaase?
my code includes following:
<link href="datepicker_dashboard.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/mootools.js"></script>
<script type="text/javascript" src="datepicker.js"></script>
</head>
<body>
<script type="text/javascript">
window.addEvent('load', function() {
new DatePicker('.date_toggled', {
pickerClass: 'datepicker_dashboard',
allowEmpty: true,
toggleElements: '.date_toggler'
});
});
</script>
<input name='date_B' type='text' value='' class='date demo_dashboard' />
for those, like me, who have to use a language with accented characters, here is a simple workaround for labels :
1- convert your character to unicode, here for example
http://people.w3.org/rishida/scripts/uniview/conversion.php
2 - insert it in the list of, say, months, like :
months: ['Janvier', 'F\u00E9vrier', etc ..
Thats it.
Thanks for this script, it looks and works great. I have 2 suggestions that I think would make the script perfect.
1. A way to spread the values across multiple inputs e.g. I could have 3 drop-downs, one for day, one for month and one for year. Updating the calendar updates the selected values in the 3 drop-downs but it also allows the user to change a date value without using the calendar. This would be very usefull for when javascript is not available.
2. When you use togglebyelement and then change the text in the textbox the output value is not updated.
I hope you consider implementing my ideas .
Thanks
Nigel
with Best Regards
Lev
if somebody has a version with the zindex can you send it? thank you in advance
z-index: 9999;
or the number that you need..
;)
Example:
"the javascript"
myDatePicker = new DatePicker('.demo_value', {
pickerClass: 'datepicker_jqui'
});
myDatePicker.onFocus($('theId'),$('theId').getNext());
"the html"
<input type="text" name="some_name" class="demo_value" id="theId" />
That´s all ! ! ! !
I hope you find this usefull.
Sorry for my low level English ;)
"2. When you use togglebyelement and then change the text in the textbox the output value is not updated."
This is essential! Now my users mistakenly think that they can alter the date by changing the text in the textbox. Please fix this soon!
Brilliant picker otherwise. :-)
"Attribution — You must attribute the work in the manner specified by the author or licensor"
How?
"DatePicker is not a constructor"
Can anyone help?
A simple problem.
The app works fine, I was able to change the date format to match that expected of MySQL. However I am having a bit of a problem with the post data.
When the date is posted it comes up as number, eg. Date selected - 2010-01-28 and the value 1262881619 gets posted. What am I doing wrong???? Or not Doing???
just notice...
you have a small bug in the functions next() and previous()
else if (this.mode == 'month') {
this.d.setMonth(this.d.getMonth() - 1);
}
should be
else if (this.mode == 'month') {
this.d.setDate(1);
this.d.setMonth(this.d.getMonth() - 1);
}
to fix next() and previous() actions from the end of the month to next month.
i.e. from 2010-01-30 -> next month ;-)
If I set 1 January 2009 (or any year) to be the minimum date, then you cannot select the 1st. The minimum is actually 2 January!
Just wanted to say I've been reviewing all the comments above and have applied all the bug fixes that I could replicate from recent comments. Please see my forked instance of the code in git repo here: http://github.com/MadmanMonty/mootools-datepicker
See the wiki page for notes on changes.
Credit to marfillaster for some of the major code updates.
If you spot any issues with my instance feel free to use the issues section in github and I'll attempt to review and resolve.
I hope these updates help some of you. Enjoy.
I am doing this in Ajax
var fm = new Element('form', {'action': '#', 'method': 'post', 'id':'FormElement'}).injectAfter(document.id('InsertionID')); // Add A Form Element to put my injected foprm into
var sp = new Element('input', {'type': 'text' , 'class' : 'date UID_1234' , 'style' : 'display : inline', 'id': 'UID_1234','value':'20, Jan 2010'}).inject(document.id('FormElement'));
// New Input Element
var sp2 = new Element('img', {'src' : 'assets/calendar.gif', 'class': 'date_toggler', 'id' : 'clickdate', 'style' : 'position: relative; top: 3px; margin-left: 4px;'}).injectAfter(document.id('UID_1234'));// new Calendar IMG To Click Onto
x1 = new DatePicker('#UID_1234', {pickerClass: 'datepicker_dashboard', allowEmpty: false, toggleElements: '.date_toggler', inputOutputFormat: 'd, M Y', onClose: function(){updateAFieldByUID('UID_1234');}});
// Add The DatePicker Class to Get It All Working.
Now I can see by the activity in the DOM that another element is being cloned.
I am however seeing this cloned element and not mine.
And when I Select the value in the datePicker It merely puts it into its newly created element in a YYYY-MM-DD format and does not show me my element again.
I understand roughly how the class is working but can't see at what point things are be hidden an shown.
N
I cant seem to find how to implement this using the Options above.
Thanks
If i attach it to input with pre-defined value "31-03-2009", and CURRENT month is February, it becomes "03-03-2009".
Problem is in unformat function. You should set year and month as soon as possible (don't forget about leap years).
Something like this:
//modified - first of all set month and year
if (a['y']) d.setFullYear(a['y'] < 30 ? 2000 + a['y'].toInt() : 1900 + a['y'].toInt());
if (a['Y']) d.setFullYear(a['Y']);
if (a['m']) d.setMonth(a['m'] - 1);
if (a['n']) d.setMonth(a['n'] - 1);
if (a['M']) {
a['M'] = this.options.months.filter(function(item, index) { return item.substring(0,this.options.monthShort) == a['M'] }.bind(this))[0];
}
if (a['F']) d.setMonth(this.options.months.indexOf(a['F']));
for (c in a) {
var v = a[c];
switch(c) {
case 'y': d.setFullYear(v < 30 ? 2000 + v.toInt() : 1900 + v.toInt()); break; // assume between 1930 - 2029
case 'Y': d.setFullYear(v); break;
case 'm':
case 'n': d.setMonth(v - 1); break;
// FALL THROUGH NOTICE! "M" has no break, because "v" now is the full month (eg. 'February'), which will work with the next format "F":
-lenkey
When I pick date only, we have both date + current time in Unixtime stamp.
pickerClass: 'datepicker_dashboard',
format: 'd-m-Y',
timePicker: true,
allowEmpty: false
});
var reqNota = new Request({
url: '',
method: 'get',
onComplete: function(response){
$('inputdate').value= '1267117200';
}
});
<input name='inputdate' id='inputdate' type='text' class='date date_toggled' style='display: inline'/>
^^
your datepicker.js is workin fine.. but i got a problem when i want to set value on my datepicker inputdate.
on the onComplete request i got nothing on my input date change... :|
$('inputdate').value= '1267117200';
how to resolve this??? pls help me.. thanks...
the year is misformated : 01/03/110
instead of : 01/03/10
in the fonction format(t, format) :
"case 'y': f += (100 + t.getYear() + '').substring(1); break"
the method getYear() seems to be deprecated in javascript.
i tryed to replace with :
"case 'y': f += (t.getFullYear() + '').substring(2);break;"
and it's works fine.
[Fri Mar 05 2010 16:17:45 GMT-0800 (PST) { $family=Object}]
while i\'m expecting something like 1268954265
Any help would be appreciated.
Best datepicker on the net so far! =)
Just one quick question though: how can I make the current day (today) to always display in different color in the month view calendar? This is useful for users to know what day it is today when they browse through different months. Help is much appreciated.
What am I doing wrong? :/
<input name="StartDate" type="text" class='demo_vista' value="">
<img src="transparent.gif" onload="new DatePicker('.demo_vista', { pickerClass: 'datepicker_vista', allowEmpty: true, format: 'm/d/Y', inputOutputFormat: 'm/d/Y' }); "/>
Now it works each time the form gets re-loaded to the page via AJAX.
Did a small "improvement". Instead of using a 4px padding to get date cells centered vertically, I used "line-height: 25px; height: 25px;" which makes them perfectly aligned.
Do keep up the good work!
This is a particular issue for form error messages, which direct the user to go back and try again. Upon going back they are greeted with a near empty form and have to re-enter their information.
tested in IE and Opera also, and they worked correctly.
Unfortunately, on IE8, the datepicker somehow changes the size of input-box. Even in the examples on this page, the input fields don't keep their css-widths of 150px, but are as wide as the page.
thank you!
I detect one bug if the month selected is march if you press botton to go one month back it goes again to march.
I developed another powerful date/time picker that uses jQuery (and an older one that uses Prototype), check it out at http://www.ama3.com/anytime/ and let me know what you think!
Can anyone help, after selecting a date from the popup I would like a form to automatically submit the form, tried a few things but getting nowhere, any help appreciated.
http://mootools.net/forge/p/mootools_datepicker
It has some additional fixes and new features too!
I wanted to let you know that in the vista CSS, line 131 (datepicker_vista .days .titles)
should also define width:100%, it helps to define it more strongly. In my page, the days got crunched without it.
Thanks.
I am actually a fresh in implementing the javascript like above, can any one please teach me help to use the script above?
I shall truly appreciate it~ thanks
Thanks for your script. Nice to have a ready made script for date inputs.
I made a modification and since you're license is to 'share alike' I thought I'd post it here as well. It adds two buttons to allow you to scroll a year per click in addition to scroll a month per click (previous/next). I made a zip with the modified files available for download at http://projects.edesign.nl/datepicker_mod.zip (contains: buttons.png, datepicker.css and datepicker.js)
--
Jurgen
> Had some problems yesterday (2010-03-31) with the dates
> displayed. An input with original value '2010-04-02'
> (YYYY-MM-DD) showed in the datepicker '2010-05-02'. When
> selecting next month from March, it gave May. Used FF3.6.2,
> MooTools 1.2, DatePicker 1.16. Today: problem gone without
> changing anything. Amazing plugin anyway!
I experienced the same issue today, and found the bug. The problem is occurring because of the way the date is being built. It begins with the current date (in your case, March 31, 2010). Then it goes through the formatting (I'll use your example to illustrate) - First it sets the year, which doesn't change. Then it sets the month to Apr 31, 2010 - and because this is not a valid date, it rolls it over to Mar 1, 2010. Then it sets the day to "2", so your result is Mar 2, 2010. This is why on April 1 you did not experience the same issue.
The fix I found is to add on line 695 the following:
d.setDate(1);
before the "for (c in a)" loop. This forces the starting date to 1, and eliminates the possibility for rolling over.
Thanks for a great plugin, by the way. I absolutely love this and use it all over the place.
I think there is a little bug in the class. In the function <b>'unformat'</b>, in the case 'j', I changed the pattern to this:
<pre>case 'j': r = '[12][0-9]|3[01]|[1-9]'; break;</pre>
Because when I put a number with two digits, it take only the first digit.
Ian
In my current application I only need the time picker, on other fields I need the date picker so I'd like to use this class for both purposes. How to set up the datepicker, only using the time picker?
I think it doesn\'t work as the other javascripts does...
ramon
if ( (d = Date.parse(item.get('value'))) != null ) {
item.set('value', d.format(this.options.format));
}
maybe anyone needs it. (Or is this possible on any other way?)
i like this one better because it has mooLang support.
But anyway: this IS definitly the BEST datepicker out there!!
to support accents for months (in FR by exemple), i replace ...set('text' by ...set('html' in renderYear method line 555 and in renderMonth method line 474
Today May 31, 2010. I am trying examples. The datepicker pop-ups very well. But when I scroll month in the future, datepicker jumps from may to july at once without June.Is it bug or feature? :-)
Ups!!! When I try to set min allowed date in 2010-06-01 datepicker shows it in 2010-07-01.
Initialize code:
new DatePicker('.date_selector_start', { pickerClass: 'datepicker_vista',
inputOutputFormat:'Y-m-d', format:'F d, Y',
minDate:{date:$('mindate').value,format:'Y-m-d'},
onSelect:function(dt){<<my ajax>>}
});
This is the first time when I get any troubles with this datepicker.
I noticed one tiny bug in it.
The calendar jumps from Mai to July.
In order to select a date within june you have to switch back to June first.
Does anybody know how to change the date in the input.
$('dob').value = '12/12/2000'
i have implement date picker success fully,
But the problem is arises when i try to implement date in smoothbox.
Kindly give me some idea
A small suggestion: I needed to combine several date/time-values into one single hidden field, but the input field that holds the datepicker's value does not fire a "change" event, so I added
609: this.input.fireEvent('change');
How I can fix it?
Please help me!!!. Thank you very much of all help.
Please help me, i can not retrieve date from my mysql db. It is just displaying recent date/time. But the date in db is previous date.
input tag is:
<input name="date_time" type="text" id="date_time" size="20" class="date date_time_piker" value="<?php echo $date_time; ?>" />
Thanks in advance.
just in case it helps anyone:
I need more complex conditions to know which dates to allow. For example I don't want the user to select weekend days. As a workaround I've patched the code adding a onSelectCheckAllowedValues event that only updates the input if a user function returns true:
to pach:
On line 77 add (and ',' on line 76 of course):
onSelectCheckAllowedValues: $empty
And on line 604 change the select method whit this:
select: function(values) {
this.choice = $merge(this.choice, values);
var d = this.dateFromObject(this.choice);
if(this.options.onSelectCheckAllowedValues(d) ) {
this.input.set('value', this.format(d, this.options.inputOutputFormat));
this.visual.set('value', this.format(d, this.options.format));
this.options.onSelect(d);
this.close(null, true);
}
},
Ideally you should check for when onselectcheckallowedvalues is not defined.. but it serves my purposes as it is now
2. Feature Request: how hard would it be to support 12 hour times? with an AM/PM that flipped as your scrolled through the hours.
This would save you a lot of code and it would be nice to be able to use your (really wonderful) picker also with the whole MT package loaded :-)
Best regards and keep being awsome!
If I use a maxdate or mindate and then open the calendar in the year view, the months are not made unavailable correctly. I fixed the issue by replacing:
var ms = ('' + this.d.getFullYear() + this.leadZero(this.d.getMonth())).toInt();
in the limited method with:
var ms = ('' + this.d.getFullYear() + this.leadZero(this.d.getMonth() + 1)).toInt();
(added "+1") Then everything works fine. Hope that helps.
Best regards.
formatMinMaxDates: function() {
if (this.options.minDate.date &&
this.options.minDate.format) {
...
}
if (this.options.maxDate &&
this.options.maxDate.format) {
...
}
}
I didn't try it for maxDate but I assume it's same fix.
if (this.options.minDate && this.options.minDate.date && this.options.minDate.format) {
I found a bug in date picker.
if i select 31st day of May and alter if i try to change the month it appears on the same month i.e May.
Simply this is for the Months which is having 31 days.
can any one let me know how it can be fixed.
Thanks,
Aejaz
I'd also suggest to add a z-index parameter to avoid hiding when used within "modal" windows (StickyWin, StickyWin.Modal, PointyTip, etc.).
On the other hand this problem can be solved in a static way by adding "z-index: 12500;" within the ".datepicker" selector.
Possible solution: kill the id property of the original (hidden) field an move it to the newly created field instead. To be able to prevent this behaviour if anybody dont want it, you count introduce a new option to control this (true/false). Should be very easy and only a few lines of code.
weekPickerOnly
yearPickerOnly
monthPickerOnly
whitelistDates
blacklistDates
minTime
maxTime
whitelistTime
blacklistTime
timeRange
dateRange
monthRange
yearRange
- Scrollwheel could be used in date, month and yearpicker, just as it works in timepicker, for better and consistent user experience.
- Booking scenario where two pickers(from,to) show with whatever setup selected(time, date etc.) and they "talk" with each other to ensure valid selections.
Just some ideas that I think would kill the competition some time into the future :)
I use your picker in a CMS.
Keep up the good work!
Very great picker but maybe not yet complete...
Here a fix for the thing @Taracque said, about the attach function:
It's all about the uncompressed code version 1.16.
1. You must give the attach function a new parameter: newvalues (line 102).
2. Then you append at line 119 this:
if (!!newvalues){
item.set('value', newvalues);
var init_clone_val = this.format(new Date(this.unformat(item.get('value'), this.options.inputOutputFormat)), this.options.format);
$(item.id + '_clone').set('value', newvalues);
} else
so it becomes at the end 'else if'.
3. At line 144 you append this:
.set('id', item.id + '_clone')
4. Try the fix in your browser.
Success with your plugin and keep going!
______________________________________
Hi All,
Please help me, i can not retrieve date from my mysql db. It is just displaying recent date/time. But the date in db is previous date.
input tag is:
<input name="date_time" type="text" id="date_time" size="20" class="date date_time_piker" value="<?php echo $date_time; ?>" />
Thanks in advance.
________________________________________
I got the same pb, any solution ?
Best regards
Is it good solution ?
If you use an input date format that specifies the month before the day, the unformat function works through it to create a date object in the same order that it finds it.
This is okay most of the time, but because it creates a date object (which defaults to today) if the month is set before the day, on in some instances it can cause issues.
Take for example today - 31st August 2010. I have an input date format of Y-m-d. The input date is 2010-09-01 (tomorrow, Sep 1st). However, the unformat function will work through this in the order year, month, date.
Date object created (defaults to Aug 31, 2010)
Year set to 2010 (Aug 31, 2010)
Month set to Sep (hang on - there's not 31 days in Sep - so it sets to Oct instead!)
Day set to 1st (Oct 1, 2010)
Obviously a temporary workaround is to use input formats that have the day before the month.
It's a great date picker though, this is the first problem I've ever had with it! Thanks!
I will like to know how I can display a list of days?
for example "01-09-2010", "03-09-2010", "10-10-2010"
Thank you for your help
var datepicker = new DatePicker('.dateField', {
pickerClass: 'datepicker_vista',
format: 'd.m.Y',
inputOutputFormat: 'Y-m-d',
allowEmpty: true,
toggleElements: '.dateToggle',
onClose: function() {
// want to do something with the current input fields:
// the hidden and the visible one. e.g:
// visible_element.blur();
// hidden_element.anythingelse();
}
});
I'm combining it with a formcheck also based on mootools. Best practice would be, to return both input fields with the function or any way similiar to that. Or I haven't found a way how I can find out the element(s). The Id of that element will do it too.
The unformat function uses this order to build a date. If you try to set the date to 31/08/2010, the picker displays 01/08/2010.
This is due to the order (day, then month, then year)
eg:
Today is 13/09/2010
I want to set the date to 31/08/2010
You set the day to 31 => 31/09/2010 (doesn't exists)
The date is considered as 01/10/2010
Then you set the month => 01/08/2010 (bug!)
Here's a quick hack:
In unformat function, line 696, insert this code:
var aSorted = {};
var aTagOrder = ['y','Y','m','n','M','F','d','j','G','H','g','h','i','s','U'];
for (var iTag = 0; iTag < aTagOrder.length; iTag ++) {
for(c in a) {
if (c == aTagOrder[iTag]) aSorted[c] = a[c];
}
}
//for (c in a) {
for (c in aSorted) { // Replacement
There should be a cleaner way to do this of course...
I checked it following: Type in the input field this date: 31.08.2010. After that clicking on calendar to see whats selected. And the correct day 31 is selected...
The bug occurs when you display the field with a value already selected.
The wrong value is in the text field (not the selector)
Before the datepicker initialization, the value in the text field is 31/08/2010:
<input type="text" value="31/08/2010" ...>
When the javascript executes, the value becomes 01/08/2010.
Agree, but your problem i cannot reproduce. But it is a bit really strange... I have a feeling that you may test your input on another computer to be really sure. Javacript's date depends on local date settings (when i'm not wrong).
I've found a bug too, that its not clearly working properly. Maybe that has to do something with each other. Refering to my configuration:
...
format: 'd.m.Y',
inputOutputFormat: 'Y-m-d',
...
my console command to check the fields:
console.log('hiddenfield.value: '+$('hiddenfield').value);
console.log('visiblefield.value: '+$('visiblefield').value);
Lets start my steps. Default is:
hiddenfield.value:
visiblefield.value:
(all ok, my values are empty by default)
Then I type in date '31.08.2010' and click somewhere out of that field, so that blur() action triggers:
hiddenfield.value: 2010-08-31T00:00:01
visiblefield.value: 31.08.2010
(see, the hiddenfield format is wrong)
I open the calendar and click on that day:
hiddenfield.value: 2010-08-31
visiblefield.value: 31.08.2010
(now its correct)
I click on the calendar icon:
hiddenfield.value: 2010-08-31
visiblefield.value: 31.08.2010
(nothing changed)
and then clicking somewhere else than calendar (so that calendar closes without a change):
hiddenfield.value: 2010-08-31
visiblefield.value: 31.08.2010
(nothing changed)
clicking into field that it gains focus:
hiddenfield.value: 2010-08-31
visiblefield.value: 31.08.2010
(nothing changed)
clicking somewhere out of that field, so that blur() triggers:
hiddenfield.value: 2010-08-31T00:00:01
visiblefield.value: 31.08.2010
(seems that the datepicker do something wrong on the blur() event)
thx
<input type="text" name="dtTest" id="dtTest" value="31/08/2010" />
<script type="text/javascript">
window.addEvent('domready', function(){
new DatePicker('#dtTest', {
pickerClass: 'datepicker_vista',
allowEmpty: true,
format: 'd/m/Y',
inputOutputFormat: 'd/m/Y'
});
});
</script>
When the page is loaded '01/08/2010' is displayed in the input. '31/08/2010' is expected. No need to click anywhere.
I'm sure the bug is not related to a specific browser. It has been reported by several users with different configurations.
Maybe you can check the behaviour of the "unformat" function in detail and try to see why and when it breaks.
I think it's impossible to know which picker raised the event without knowing the id.
Maybe you should not use directly a css selector but a loop:
<input type="text" name="test1" class="dateField" />
<input type="text" name="test2" class="dateField" />
<script type="text/javascript">
function attachField(oField) {
new DatePicker(oField, {
pickerClass: 'datepicker_vista',
format: 'd.m.Y',
inputOutputFormat: 'Y-m-d',
allowEmpty: true,
onClose: function() {
alert(oField.value);
alert(oField.getNext().value);
}
});
}
window.addEvent('domready', function(){
var aFields = $$('.dateField');
for (var iField = 0; iField < aFields.length; iField ++) {
// You must use a function, otherwise oField would be the same for each loop
attachField(aFields[iField]);
}
});
</script>
one problem is when I tried to set up format: %Y-%m-%dT%H:%i, the input date field showed like '2010-09-22T11:i', 'i' didn't changed to what I wanted number. could someone tell how to fix it, sorry I am not an expert on javascript.
Thanks!!!
it works well but not works in run time or when i create it dynamically.
my code:
java script :
<script type="text/javascript">
<!--
window.addEvent('domready',function(){
var debugElmt = document.id('debug');
var debug = function(txt){
debugElmt.set('text',txt);
}
// Dashboard skin
new DatePicker($$('.date_toggled'), { pickerClass: 'datepicker_dashboard', toggleElements: '.date_toggler' });
// MooTools.lang support
new DatePicker('i18n', {
positionOffset: { x: 0, y: 5 },
format: '%d-%m-%Y'
});
});
html:
<input type="button" value="Add More (if needed)" name="eduAdd" onClick="LoadAcademicForm(form1);" class="button"/>
javascript:
function LoadAcademicForm
{
<input type='text' id='txtServedFrom"+(i_exp+1)+"' name='txtServedFrom"+(i_exp+1)+"' readonly='true' value='' class='date date_toggled' style='display: inline'/><img src='images/calendar.gif' class='date_toggler' style='position: relative; top: 3px; margin-left: 4px;' />
}
plz help some1!!
Maybe the focus event helps you. If you have a checkbox make a onclick event like:
$('id_checkbox').addEvent('click', function() {
if(this.checked == "checked") { // or maybe you have to use $('id_checkbox') instead of this, that i havnt tested
$('id_inputfield').focus();
} else {
// do anything when checking box off (delete date or something
}
}
That works if you've configured your datepicker showing up the calendar when you click into the input field.
I have tracked it down to the following pseudo logic
assuming it is september (or any month < 31 days)
Unformat gets the current date 22-Sep-2010,
gets the day from input 31-Mon-yyyy as 31
calls d.setDate(v) which sets the date to 01-Oct-2010
the month is set to Jan
the year is set to 2010
The display date is now incorrectly set to 01-Jan-2010 where it should be 31-Jan-2010
My work around is to store the day on the case 'j': and call d.setDate(day) at the end of the calculations
add new variable to function header
var day;
case j becomes
case 'j': day = v; d.setDate(v); break;
before the return add
d.setDate(day);
IMHO it is not necessary to call the d.SetDate i the case 'j'
I include my debugging code below
Many thanks for your Class, please let me know if I can give you any further information
Rgds Dave
unformat: function(t, format) {
var d = new Date();
var a = {};
var c, m;
t = t.toString();
var day;
var myMessage = '';
myMessage += "\n input t " + t;
myMessage += "\n format " + format;
for (var i = 0; i < format.length; i++) {
c = format.charAt(i);
switch(c) {
case '\\': r = null; i++; break;
case 'y': r = '[0-9]{2}'; break;
case 'Y': r = '[0-9]{4}'; break;
case 'm': r = '0[1-9]|1[012]'; break;
case 'n': r = '[1-9]|1[012]'; break;
case 'M': r = '[A-Za-z]{'+this.options.monthShort+'}'; break;
case 'F': r = '[A-Za-z]+'; break;
case 'd': r = '0[1-9]|[12][0-9]|3[01]'; break;
case 'j': r = '[1-9]|[12][0-9]|3[01]'; break;
case 'D': r = '[A-Za-z]{'+this.options.dayShort+'}'; break;
case 'l': r = '[A-Za-z]+'; break;
case 'G':
case 'H':
case 'g':
case 'h': r = '[0-9]{1,2}'; break;
case 'a': r = '(am|pm)'; break;
case 'A': r = '(AM|PM)'; break;
case 'i':
case 's': r = '[012345][0-9]'; break;
case 'U': r = '-?[0-9]+$'; break;
default: r = null;
}
if ($chk(r)) {
m = t.match('^'+r);
if ($chk(m)) {
a[c] = m[0];
t = t.substring(a[c].length);
} else {
if (this.options.debug) alert("Fatal Error in DatePicker\n\nUnexpected format at: '"+t+"' expected format character '"+c+"' (pattern '"+r+"')");
return d;
}
} else {
t = t.substring(1);
}
}
for (c in a) {
var v = a[c];
switch(c) {
case 'y': d.setFullYear(v < 30 ? 2000 + v.toInt() : 1900 + v.toInt()); break; // assume between 1930 - 2029
case 'Y': d.setFullYear(v); break;
case 'm':
case 'n': d.setMonth(v - 1); break;
// FALL THROUGH NOTICE! "M" has no break, because "v" now is the full month (eg. 'February'), which will work with the next format "F":
case 'M': v = this.options.months.filter(function(item, index) { return item.substring(0,this.options.monthShort) == v }.bind(this))[0];
case 'F': d.setMonth(this.options.months.indexOf(v)); break;
case 'd': myMessage += "\nc = d case:d v = " + v;
case 'j': day = v; myMessage += "\nc = d case:j v = " + v; myMessage += "\nd " + d; d.setDate(v); myMessage += "\nd " + d; break;
case 'G':
case 'H': d.setHours(v); break;
case 'g':
case 'h': if (a['a'] == 'pm' || a['A'] == 'PM') { d.setHours(v == 12 ? 0 : v.toInt() + 12); } else { d.setHours(v); } break;
case 'i': d.setMinutes(v); break;
case 's': d.setSeconds(v); break;
case 'U': d = new Date(v.toInt() * 1000);
}
};
myMessage += "\nsetting day " + day;
d.setDate(day);
myMessage += "\nreturning " + d
alert (myMessage);
return d;
}
In lot of languages 2-letters small names not same as first 2 letters of day name. Are possible add some kind of dayShortArr to be able set correct names?
And for months same
I found a bug / problem in your datepicker, which works fine except for that little bug.
The bug is in the "unformat" function.
In some countries they write a date in the format dd/mm/yyyy instead of yyyy/mm/dd.
Suppose it is now "2010/09/30" or in my country "30/09/2010".
Suppose my input date is "31/08/2010".
In your code, this happens:
**************************
var d = new Date(); //d is now "30/09/2010", the current date
**************************
Next you split my input date "31/08/2010" into parts and do this:
*************************
d.setDate(31); //date is now "01/09/2010" because there is no date 31 in sempteber, this is the problem.
*************************
To fix the problem, you have to set the date after all the other properties have been set.
You could do this by declaring a variable "var new_date = null;" just before the for-loop.
Next thing is to replace "d.setDate(v);" with "new_date = v;"
Finally, just after the for-loop you put the text "if(new_date !== null) d.setDate(new_date);"
This should solve the problem.
It's very simple and looks awesome!
Thanks.
Just one comment: With the InputOutputFormat Y/m/d (standard for Mysql) if you leave the value in HTML untouched (value='')
Today's date will show in the input box but on submit the value will return nothing. You need to manually add today's date into the input box value.
Example:
<input type='text' name='datemade' class='date dateField' value='<?=date('Y/m/d')?>' />
'this.picker' is null or not an object
datepicker.js Line 587
Code:0 Char:3
URI: http://www.certificates4u.co.uk/javascripts.datepicker.js
The Yellow Triangle & Error shown at bottom of page, and - maybe related, the scrollbar will not work.
I have used the unsquashed version her (Tried earlier squashed version earlier - no difference)
Thanks for a great piece of software
Steve
My solution is not very elegant.
var tmp = sdt.getDate();
sdt.setDate(sdt.getDate() + 1);
if(tmp == sdt.getDate())
sdt.setTime(sdt.getTime() + 3600000);//3600000 = 1 hour
Thanks,
Guilherme.
In 'formatMinMaxDates' you cannot assign directly the options 'this.options.minDate' (resp. maxDate in the rest ot the post) with the unformated value because it is used at every focus (indeed, 'show' function calls 'formatMinMaxDates' every time).
One solution is simply to assign 'this.options.minDate.whatever' instead of 'this.options.minDate' in 'formatMinMaxDates', and change 'this.options.minDate' in the whole script (except in the '$chk's of course).
For the rest, your work is really awesome, thanks a lot!
thanks
is there any method to make it visible always?? Not only after clicking on some element.
Great tool. Thanks.
HTML:
<h3>Date range</h3>
<input name="date_from" id="date_from" size="8" maxlength="11" value="<?=date('Y-m-d'); ?>" /> – <input name="date_to" id="date_to" size="8" maxlength="11" value="<?=date('Y-m-d'); ?>" /><br />
<div class="form_help">Date from – Date to. Select period for the banner to show.</div><br />
JS:
<script type="text/javascript">
<!--
window.addEvent('domready', function(){
new Picker.Date('date_from', {
format: '%Y-%m-%d',
minDate: '<?=date('Y-m-d'); ?>',
onSelect: function() {
$('date_to').value = $('date_from').value;
tc.initialize('date_to', {
minDate: $('date_to').value
}
);
}
});
var tc = new Picker.Date('date_to', {
format: '%Y-%m-%d',
minDate: $('date_to').value
});
});
//-->
</script>
Anyone an idea or solution??
I am really missing a function that allows me to pick a year (40, 50, etc. years back) - without having to click 50 times ... anyone out there who would?
var init_visual_date, d = visual_input.getCoordinates();
insted of visual_input should be original_input because it possitions the calender tottaly wrong when trying to get position of display:none element.
Just what I needed - I'll make a donation right away!
format: 'j.n.Y. H:i',
inputOutputFormat: 'j.n.Y H:i:s',
the script doesn't correctly recognize the input date and resolves this
17.1.2011 00:00:00
into
1.11.2011. 00:00
The date is OK when I save it, so it seemes to be the problem of the "input" part. It also doesn't matter how I change the displayed format, I just keep getting the 1 Nov 2011. I should add that this problem appears with the latest 1.3 version of Mootools…
This causes all sorts of problems when using times in calculations, or even just storing the values in the database in Y/m/d H:i:s format. You end up with entries like this:
01/01/2011 00:00:24
02/02/2011 00:00:38
Where the seconds have been taken from the system time, rather than being set to zero.
I implement the datepicker and some inputs in <tds> and i want to clone all the line (<tr>). when the line is cloned datepicker won't work, how to reattach event to the new cloned element.
Nota : "cloneEvent" won't work as i want. onClick the cloned datepicker, the previous input is filled
an ugly bug for us who use format d.m.Y:
bug appers only if current month has less than 31 days and a date with day-number greater than max-day-number in current month is to be displayed. it displays inproperly - e.g. 31.1.2010 is displayed as 3.1.2010.
to correct:
add 2 lines in unformat function (after line 650 in original
js) to set d to january 1st:
unformat: function(t, format) {
var d = new Date();
d.setMonth(0);
d.setDate(1);
...
:-)
also i've upgraded this library to colorize holidays, including easter monday. if someone is interested...
in case you'd like to use DatePicker with MooTools FX-Tween CSS3 (http://mootools.net/forge/p/fx_tween_css3)
Change line 319 (FX-Tween CSS3 allows short notated transitions; unit is obligatory in this case):
transition: Fx.Transitions.Quad.easeInOut
to
transition: "quad:out", unit: "px"
Change line 296 (FX-Tween CSS3 has problems with tweening to 0)
tween('left', -this.bodysize.x, 0);
to
tween('left', -this.bodysize.x, 1);
E.g. disable select past dates, for example when asking user to set an appointment date (not logical to set appointment for last week...).
E.g. disable select future dates, for example when asking user to select dates for running reports on data (not logical to set future dates as reports only process existing data).
I'm not too big a fan of the separate pick-date-first,-then-show-time style either, perhaps an option to show time below the calendar, like pretty much most other datetime pickers do?
I've only got those two issues, but not having them is a dealbreaker. It's a shame, would really have liked to support this as it's easily one of the best looking javascript datepickers I've seen.
I'm trying to use it with MooTools 1.3, but since version 1.3 the Browser.Engine object is deprecated. So DatePicker errors on that instruction. Any news on an update for Moo 1.3? Thx!
when i use this class, i can't attach a personal function with event.
For Ex onkeyup="myfunction(event)"
my event is always undefined.
I sue the event to format the date when inserted manually. add backslashes ecc ecc.
There is a way to solve it?
Thanks a lot for this incredible tool !!
Just a bug you can correct like this :
line 155:
item.set('value', clone.get('value'));
must be corrected like this :
value = this.unformat(clone.get('value'), this.options.format);
item.set('value', this.format(value, this.options.inputOutputFormat));
bye
if(clone.get('value') == ''){
item.set('value', '');
} else {
value = this.unformat(clone.get('value'), this.options.format);
item.set('value', this.format(value, this.options.inputOutputFormat));
}
I can't get it work, that only days in the future are selectable in the date picker. Can somebody please tel me if and if yes, how it is possible to make only dates from tomorrow onward selectable?
Your help would be highly appreciated.
Thanks in advance.
Regards,
Bromm
The time picker is a great idea !
thanks a lot
In my case, I configured the DatePicker initially as shown below
var dp = new DatePicker('.start_date_picker', {format: 'm-d-Y', inputOutputFormat: 'Y-m-d', positionOffset: { x: 0, y: 5 }, minDate: {date: '<%= Date.today.to_s %>', format: 'Y-m-d'}, maxDate: {date: '<%= ((Date.today)+13.days).to_s %>', format: 'Y-m-d'}});
It "appeared" to be working properly, initializing to today's date in the form. However, when you actually submit the form, it doesn't submit the field that you see, it submits another hidden field. You can see this by setting debug: true to in your options. I solved the problem by explicitly initializing the value to today's date in my actual form field like this:
<input id="lead_start_date" name="lead[start_date]" class='date start_date_picker' type="text" value="<%= Date.today.to_s %>">
I would like to donate, but dont have PayPal :(
I try to use DatePicker inside SqueezeBox and I have some problems.
The container of date picker is below squeezebox. Is there an issue to fix this problem?
One question: I have been using this for more than a year with no problems. Now, within the past month or so, only for some of my visitors, the displayed day of the week is off by one day. For example, Oct 1 2011 is a Saturday, but the calendar shows it as being a Friday. I'm still trying to find out which browser those visitors were using. Could it be IE9?
One feature request: Some way to offset the time so the client side matches up with the server time input value.
Thanks!
Thank you for your excellent work. I just have a suggestion, can you please add a Day Off feature so nobody can select a specific day of a week, like myself as a restaurant owner, I do close my place every Tuesday and I use your Datepicker for my reservation form.
Thanks for reading and keep up the good work !
Howard
working with joomla, crossbrowser without problems!!!
thank you for your work and time
window.addEvent('load', function() { new DatePicker('.demo_allow_empty', { pickerClass: 'datepicker_dashboard', allowEmpty: true }); }); Datepicker starting at and allowing no value: <with the textbox beside that code> what do i need to do? Thanks :)
Little contribution (based on rob comment on 18-11-2009, 08:03) for manual input and with date format dd/MM/YYYY, this modification allows:
.- Manual input with digit verification
.- On blur it validates the date, if invalid, then sets empty string
Alterations on are in method attach (for version 1.16).
Search for "clone.addEvents({" and replace with the following:
'blur': function() {
if (! new Date(clone.get('value')).isValid()) {
clone.set('value', '');
}
item.set('value', clone.get('value'));
}
Search again for "clone.addEvents({" and replace with the following:
'keydown': function(e) {
/*if (this.options.allowEmpty && (e.key == "delete" || e.key == "backspace")) {
item.set('value', '');
e.target.set('value', '');
this.close(null, true);
} else*/ if (e.key == "tab") {
this.close(null, true);
} else if (e.key == '0' || e.key == '1' || e.key == '2' || e.key == '3' || e.key == '4' || e.key == '5' ||
e.key == '6' || e.key == '7' || e.key == '8' || e.key == '9' || e.key == "backspace") {
if (e.key != "backspace") {
if (item.datepickerField.value.length == 0) {
if (!(e.key == '0' || e.key == '1' || e.key == '2' || e.key == '3')) {
e.stop();
}
} else if (item.datepickerField.value.length == 1) {
if (item.datepickerField.value == '3' && !(e.key == '0' || e.key == '1')) {
e.stop();
} else if (item.datepickerField.value == '0' && e.key == '0') {
e.stop();
}
} else if (item.datepickerField.value.length == 2) {
if (!(e.key == '0' || e.key == '1')) {
e.stop();
} else {
item.datepickerField.value += "/";
}
} else if (item.datepickerField.value.length == 4) {
var lastDigit = item.datepickerField.value.split('')[item.datepickerField.value.length - 1];
if (lastDigit == '0' && e.key == '0') {
e.stop();
} else if (lastDigit == '1' && !(e.key == '0' || e.key == '1' || e.key == '2')) {
e.stop();
}
} else if (item.datepickerField.value.length == 10) {
e.stop();
} else if (item.datepickerField.value.length == 5) {
item.datepickerField.value += "/";
}
} else {
if (item.datepickerField.value.length == 4 || item.datepickerField.value.length == 7) {
item.datepickerField.value = item.datepickerField.value.substring(0, item.datepickerField.value.length - 1);
}
}
} else {
e.stop();
}
}.bind(this),
'focus': function(e) {
this.onFocus(item, clone);
}.bind(this),
'keyup': function(e) {
this.input.set('value', this.visual.get('value'));
}.bind(this)
Sorry for the big code, but was the fasttest way to debug it. Hope can help you.
I do not know how I switch my datepicker in German, so that it enters by clicking the calendar German date format (d.m.Y) in the text box.
Can someone help me?
Regards
Tom
Narendran .N
Tweet me @MyNaren89
I have the mootools core being referenced through the GoogleAPIs URL as follows:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.1/mootools.js"></script>
I use the JavaScript to call the new DatePicker() function.
I get nothing at all when I click into the form field that I need this specified on. What am I missing?
When you declare a new datepicker with
var foo = new DatePicker(....
it puts a default date (today date) on the input.
If a user dont select another date, just let the default one, i cant get this date by javascript. If i try to get it with
$('idDate').value, this values is empty.
Is my fault or just a problem with the datepicker
Thanks in advance
I have made a few minor functionality changes that allow for a bit more expansive control of the dp. I added in an option to assign an ID to the newly created form element at the time of initialization. This allowed me to access the values of one datepicker in order to modify another datepicker to restrict the date. This also allowed me to set the focus on a particular date picker after another had been completed. I found this very useful and required in order to use the script for checkin and checkout dates.
With a little math I was even able to tie the values back into a selected number of nights and when any of the 3 fields are changed they all are updated to reflect the new values.
I have been developing in php for years but have never been good with java. Thus I have had to rely on other's datepickers and this was by far the best javascript datepicker I have found.
Donation will follow shortly.
see my implementation at jacksonhole(dot)net. Live in the next day or 2
Me and my friend used this in our project, and since we're not that good in programming, this was really helpful!
We have a problem though, when we want to choose a date in December, we get a bug. Not in any other month, just December.
What happens is that we choose a date in the calendar, and then we're supposed to choose a time, but we have to click somewhere in the box before we can change the time, and when we click in the box, we "choose" another date even though the calendar isn't there. When we've done it, we can choose a time, but the time doesn't change from the current time in the form..
I'ts really hard to explain but I hope I made myself clear..
does anyone know how to fix this?
Me and my friend used this in our project, and since we're not that good in programming, this was really helpful!
We have a problem though, when we want to choose a date in December, we get a bug. Not in any other month, just December.
What happens is that we choose a date in the calendar, and then we're supposed to choose a time, but we have to click somewhere in the box before we can change the time, and when we click in the box, we "choose" another date even though the calendar isn't there. When we've done it, we can choose a time, but the time doesn't change from the current time in the form..
I'ts really hard to explain but I hope I made myself clear..
does anyone know how to fix this?
If anyone can see my no doubt schoolboy error, do let me know.
I ended up here instead http://jqueryui.com/demos/datepicker/ and hey, that worked.
I have one issue, and I would be thankful if you can help me out. I am trying to set the date after binding the input field to the plugin instance (after calling new DatePicker()). Apparently it is setting the date (when I click on the field I can see that the wanted date is highlighted), BUT the problem is that the input field's text doesn't change to reflect the new value which I am trying to set.
I thought about unbinding the field and the instance but I couldn't figure out how to do it. I thought about removing the input field then adding it again but then flickering will be ugly.
Plz, I would really appreciate your help on this.
For example, if you making some applications with date of birth, you don't know exact hour and minute when someone was born. So, it's better to offer "00:00" in such case. Any idea?
this looks great.
is it possible to set the minutes in 5 or 15 minute increments?
thanks!
Just replaced all my old date pickers for this one.
When the datepicker appears and disappears - the only way to get it back it to click off the input box and then click back on it.
Any ideas about what to do about these issues?
thanks
I did use the form "Toggle by Element" (as the example) and the the registry "input_date" appear as "1335217230" into database.
How to register "input_date" as "Abr 04 2012" or similar format into database?
Thanks for your help. (BTW great tool)