Skip to content Skip to sidebar Skip to footer

JQuery UI Datepicker GetDate Returns Today's Date On Invalid Date

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 toda

Solution 1:

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);
}

Post a Comment for "JQuery UI Datepicker GetDate Returns Today's Date On Invalid Date"