我正在尝试使用 Bootstrap 验证器重置表单
当我单击“重置”时,它会删除输入值,但是当我单击“提交”时,即使输入为空,它仍然会提交,而此时应该显示错误
这是js
$('#shortener').bootstrapValidator({
container: '#sstatus',
fields: {
url: {
validators: {
notEmpty: {
message: 'Enter a url!'
},
uri: {
message: 'URL is not a valid url, include http://'
}
}
}
}
}).on('success.form.bv', function(e) {
// Prevent form submission
e.preventDefault();
console.log('in');
// Get the form instance
var $form = $(e.target);
// Get the BootstrapValidator instance
var bv = $form.data('bootstrapValidator');
// Use Ajax to submit form data
$.post('ajax/new_url.php', $form.serialize(), function(result) {
console.log('works'+result.message);
$('#shortener').fadeOut('fast', function(){
$form.bootstrapValidator('resetForm', true);
});
$(document).on('click', '#shorten_again', function(e){
e.preventDefault();
});
}, 'json');
});
最佳答案
$('form').bootstrapValidator('resetForm', true);
关于jquery - Bootstrap 验证器重置表单不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27314861/