Date validation using bootstrap validator using datePicker

3k views Asked by At

I am trying to validate the date but the problem which I am facing is that when I am selecting the date first time it validates easily.

But when I am trying to select the date once again from datepicker, it does not validates again. I tried revalidating it, but it didn't work.

I also tried using datetimepicker but the result was the same.

JavaScript

$(document).ready(function() {
      $('#datePicker')
        .datepicker({
          format: 'dd-mm-yyyy'
        })
        .on('changeDate', function(e) {
          // Revalidate the date field
          $('#defaultForm').data('bootstrapValidator').revalidateField('loc_date');
        });
      $('#defaultForm').bootstrapValidator({
          message: 'This value is not valid',
          //        live: 'disabled',
          feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
          },
          fields: {
            loc_date: {
              message: 'The Date is not valid',
              validators: {
                date: {
                  format: 'dd-mm-yyyy',
                  message: 'The value is not a valid date'
                }
                /*,
                  notEmpty: {
                  message: 'The Date is required and can\'t be empty'
                }*/
              }
            }
          });
      });

HTML

<div class="form-group">
  <label class="col-lg-3 control-label">Assign Date*</label>
  <div class="col-lg-5 input-group input-append date" id="datePicker">
    <input type='text' class="form-control" placeholder="dd-mm-yyyy" name="loc_date" />
    <span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>
  </div>
</div>
0

There are 0 answers