我正在使用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);
}
});
});
答案 0 :(得分: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
}
});
});
答案 1 :(得分: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 () {
});