0

我正在尝试验证日期,但我面临的问题是,当我第一次选择日期时,它很容易验证。

但是当我尝试再次从 datepicker 中选择日期时,它不会再次验证。我尝试重新验证它,但它不起作用。

我也尝试使用 datetimepicker,但结果是一样的。

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>
4

0 回答 0