Date time picker - validate date

1k views Asked by At

I am having an issue trying to validate a manually entered date with the date time picker.

I have seen similar questions where the solution was to make the field read only so they need to use the calendar. That is not an option because we want to allow the user to manually enter the date.

My issue seems to be with validateOnBlur. If I set it to true it automatically changes the value to the current time, I want to leave what they keyed in and show an error message. The issue there is that if validateOnBlur is set to false it doesn't execute the onChangeDateTime block, so I cannot validate the value.

It only seems to be an issue with an invalid format. If I enter 06/09/2015 11:77 it executes the onChangeDateTime block and my invalid date message is displayed. However, if I enter 06/09/2015 1177 it either changes the value to the current time (validateOnBlur=true) or doesn't execute the onChangeDateTime code (validateOnBlur=false).

Am I missing something? Is there another option I need to set? Any suggestions to correct this?

Here is the block where I create the datetimepicker:

form.find("#effectiveFromDate").datetimepicker({
    format:"m/d/Y H:i",
    formatDate:"m/d/Y",
    formatTime: "H:i",
    timepicker: true,
    validateOnBlur: true,
    step:5,
    minDate: minDate,
    maxDate: maxDate,
    onChangeDateTime: function(ev){
        validateFromToDates(form, minDate, maxDate);
    }
})
0

There are 0 answers