Bootstrap datepicker和bootstrap验证器 [英] Bootstrap datepicker and bootstrap validator

查看:216
本文介绍了Bootstrap datepicker和bootstrap验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此处的引导日期戳记,并从这里。我也使用bootstrap v3.1.1。

I am using the bootstrap datepicker from here and the bootstrap validator from here. Also I am using bootstrap v3.1.1.

从datepicker中选择一个日期后,验证器不会反应。这是我使用键盘输入日期的唯一方法。

After selecting a date from datepicker the validator does not react. It works just when I use the keyboard to enter a date.

这是我的HTML代码:

Here is my HTML code:

<form id="myForm" method="POST"> 
   <div class="col-lg-3">
     <div class="form-group">
        <input name="endDate" type="text" class="datepicker form-control">
     </div>
   </div>
</form>

在.js文件中我添加了:

In .js file I added:

$(document).ready(function () {
  $('.datepicker').datepicker();
)};

和验证器:

$(document).ready(function () {
    $('#myForm').bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            endDate: {
                validators: {
                    date: {
                        format: 'DD/MM/YYYY',
                        message: 'The format is dd/mm/yyyy'
                    },
                    notEmpty: {
                        message: 'The field can not be empty'
                    }
                }
            }
        }
    });
});


推荐答案

使用BootstrapValidator与Bootstrap-datetimepicker或Bootstrap-datepicker ,你应该重新验证日期字段。

When using BootstrapValidator with Bootstrap-datetimepicker or Bootstrap-datepicker, you should revalidate the date field.

所以你应该添加这个:

1)使用bootstrap- datetimepicker:

1) using with bootstrap-datetimepicker :

$('.date')
    .on('dp.change dp.show', function(e) {
        // Revalidate the date when user change it
        $('#myForm').bootstrapValidator('revalidateField', 'endDate');
});

2)使用bootstrap-datepicker:

2) using with bootstrap-datepicker :

$('.datepicker')
    .on('changeDate show', function(e) {
        // Revalidate the date when user change it
        $('#myForm').bootstrapValidator('revalidateField', 'endDate');
});

请参阅 datetimepicker示例获取更多信息。

这篇关于Bootstrap datepicker和bootstrap验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆