I am trying to get my head around using jQueryUI DatePicker. One of the main things I must understand is the way a date can be set on page load.
After doing some research, I found 2 different ways to do this:
defaultDate optionsetDate methodThe main difference I found out so far is that the defaultDate option only sets the value in the datePicker calendar itself.
Whereas the setDate method sets both the date in the input type text & in the datePicker calendar itself.
One interesting thing is that when using setDate method & defaultDate option simultaneously, the date set using setDate method overrides the value of the date set using the defaultDate option.
see http://jsfiddle.net/vb7mu3sf/
Another couple of differences I noticed:
defaultDate option accepts additional types (Number & String).setDate method can of course be called at anytime on the datePickerIs there anything else I missed about their differences?
Resources:
Have a look at the documentation:
defaultDate
Set the date to highlight on first opening if the field is blank.setDate
Sets the date for the datepicker.
There is not much left to explain. As mentioned above:
defaultDate property:
setDate method:
Possible uses of one technique or the other:
setDate method. This saves two clicks if the user is OK with the pre-entered date.defaultDate to specify the date that is focused should the user choose to activate the datepicker.Notes:
... but defaultDate option accepts additional types (Number & String).
Actually, setDate accepts all versions of date that defaultDate does.
setDatemethod can of course be called at anytime on the datePicker
Well, the defaultDate option can be set anytime as well. For example, if there are two calendars e.g. checkin and checkout and the user chose a checkin date Nov 10, 2014 then you would want to set the defaultDate on the other calendar to be Nov 11, 2014.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With