When using jQuery UI's date-picker, if you call getDate while the text in the text box is not a valid date, getDate returns today's date.
Example
How can I distinguish between today's date and an invalid date when retrieving the date?
Looks like this is normal behaviour for the widget. Here's a function that includes support for invalid date checking:
/* Gets the current value
* @return Date The result or null if no date is present
* @throws If the entered value is invalid
*/
function getDate(datePicker) {
datePicker = $(datePicker);
var format = datePicker.datepicker("option", "dateFormat"),
text = datePicker.val(),
settings = datePicker.datepicker("option", "settings");
return $.datepicker.parseDate(format, text, settings);
}
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