2

我正在使用 Bootstrap 验证器,我遇到的问题是我想在所有值都有效但无法这样做之后启用提交按钮。

$(document).ready(function() {
    $('#ans_frm').bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        submitButtons: 'button[type="submit"]',
        fields: {
            ans: {
                group: '.col-md-8',
                validators: {

                    stringLength: {
                        min: 3,
                        max: 100,
                        message: 'The answer must be more than 2 and less than 100 characters long'
                    },
                    notEmpty: {
                        message: 'The answer must not be empty'
                    }
                }

            }
        }
    }).on('status.field.bv', function(e, data) {

                disableSubmitButtons(false);
            }
        });
});
4

2 回答 2

3

您需要禁用提交按钮.on('error.field.bv')并重新启用它.on('status.field.bv')

你应该使用data.bv.disableSubmitButtons()方法!

你能试试这个吗?

$(document).ready(function() {
    $('#ans_frm').bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        submitButtons: 'button[type="submit"]',
        fields: {
            ans: {
                group: '.col-md-8',
                validators: {
                    stringLength: {
                        min: 3,
                        max: 100,
                        message: 'The answer must be more than 2 and less than 100 characters long'
                    },
                    notEmpty: {
                        message: 'The answer must not be empty'
                    }
                }
            }
        }
    }).on('error.field.bv', function(e, data) {
            data.bv.disableSubmitButtons(true); // disable submit buttons on errors
        }
    }).on('status.field.bv', function(e, data) {
            data.bv.disableSubmitButtons(false); // enable submit buttons on valid
        }
    });
});
于 2014-11-04T23:42:12.133 回答
2

用这个

$('#ans_frm').bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            live: 'enabled',
            trigger: null
        }).on('success.form.bv', function (e) {
            // Prevent submit form
            // e.preventDefault();
        })
      .on('error.form.bv', function () {

      });
于 2014-11-19T13:29:06.400 回答