Search code examples
javascriptjquerydatetimepicker

On Change validate field - datetimepicker


I have a field that utilizes a date picker as well as a validator. In the example below, I have pre-filled the date input. Now, erase the data and you will see it is no longer valid. Then click on the calendar icon to select a date. It does not re-validate until you move away from the input (blur), but I would rather it validate any time new text is entered from the date selector. Any suggestions?

JSFiddle

$(document).ready(function () {
    $('#app').bootstrapValidator();
});

$("#dob").on('blur', function () {
    $('#app').bootstrapValidator('revalidateField', 'dob');
});

$(function () {
    $('#dobpicker').datetimepicker({
        pickTime: false,
    });
});

Solution

  • You can do it like this:

     $("#dobpicker").on("dp.change",function (e) {
          $('#app').bootstrapValidator('revalidateField', 'dob');      
     });
    

    Working Fiddle