我有一个表单,我使用了字段验证器并且工作正常但是当我在编辑模式下打开表单并且空字段并按下save bootstrap验证器不起作用。
以下是验证码
$(document).ready(function () {
$('#frmSpecialtyDetail')
.bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
ShortName: {
group: '.col-md-6',
validators: {
notEmpty: {
message: 'Short Name is required'
}
}
}
}
});
});
答案 0 :(得分:0)
从最初的BootstrapValidator网站获取,这是您必须使用的代码,以便在表单验证成功后提交表单:
$(document).ready(function() {
$(form)
.bootstrapValidator({
... options ...
})
.on('success.form.bv', function(e) {
// Prevent form submission
e.preventDefault();
// Get the form instance
var $form = $(e.target);
// Get the BootstrapValidator instance
var bv = $form.data('bootstrapValidator');
// Use Ajax to submit form data
$.post($form.attr('action'), $form.serialize(), function(result) {
// ... Process the result ...
}, 'json');
});
});
在你的情况下,我会按照以下方式做点什么:
$(document).ready(function() {
$('#frmSpecialtyDetail')
.bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
ShortName: {
group: '.col-md-6',
validators: {
notEmpty: {
message: 'Short Name is required'
}
}
}
}
})
.on('success.form.bv', function(e) {
// Prevent form submission
e.preventDefault();
// Get the form instance
var $form = $(e.target);
// Get the BootstrapValidator instance
var bv = $form.data('bootstrapValidator');
// Use Ajax to submit form data
$.post($form.attr('action'), $form.serialize(), function(result) {
// ... Process the result ...
}, 'json');
});
});
希望有所帮助。