我正在使用这个 Bootstrap 验证器 github.com/1000hz/bootstrap-validator 作为我的 Bootstrap 表单,但似乎无法在提交表单之前设置一些外部 JS 条件。
例如,我想从外部 JS 文件执行以下操作:
1 # 如果表单或表单的某些输入使用 validator() 无效,那么我会执行一些操作。
2 # else 用户将看到一些 Bootstrap 按钮加载消息,直到所有内容都提交到数据库中。
你可以在这里有一个案例:
$('button[data-loading-text]').click(function () {
var btn = $(this);
btn.button('loading');
$.blockUI();
// #1 if form is invalid using validator() then I unblock the please wait message $.unblockUI(); and reset the bootstrap loading button.
// #2 else users will still see the "please wait" message + bootsrap loading button untill everything is submitted into the databases.
});
http://jsfiddle.net/temgo/k07nx06k/12/
任何帮助将不胜感激,因为看起来插件事件仅针对特定字段而不是完整表单验证设置。
问候
最佳答案
查看 1000hz 页面上的事件部分。 ( http://1000hz.github.io/bootstrap-validator/#validator-events )
如果您想在验证之前启动操作 - 只需监听该事件即可。
$('#someFormId').on('validate.bs.validator', function(){
doSomeStuff();
});
编辑
事件的问题是它在每个字段之后触发。据我所知,此插件不提供完成成功验证的事件。
关于javascript - Bootstrap JS 验证器和表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27011984/