Ada*_*son 1 validation modal-dialog twitter-bootstrap
经过对网络和pugin文档的长期研究后,我正在写这个问题.我可能在这里错过了什么,但我找不到什么.
我正在使用bootstrapvalidator(http://bootstrapvalidator.com/)插件来尝试验证bootstrap模式中的表单.
我的表格代码:
<form method="POST" action="/venues/update" accept-charset="UTF-8" id="editForm">
<input name="id" type="hidden" value="XYZ">
...
[other form fields...]
...
<button type="submit" class="btn bg-black">Modifier</button>
</form>
Run Code Online (Sandbox Code Playgroud)
我的js代码验证:
$('#editForm')
.bootstrapValidator({
message: 'Cette valeur ne peut pas être utilisée.',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
submitHandler: function(validator, form, submitButton) {
alert('submit!!');
},
fields: {
venue_name: {
message: 'Ce nom n\'est pas valide.',
validators: {
notEmpty: {
message: 'Le nom du lieu ne peut pas être vide.'
},
stringLength: {
min: 5,
max: 30,
message: 'Le nom doit être d\'au moins 5 caractères'
},
regexp: {
regexp: /^[a-zA-Z0-9_ ]+$/,
message: 'Le nom ne peut pas contenir de caractères spéciaux.'
}
}
},
max_capacity: {
message: 'Cette valeur n\'est pas valide.',
validators: {
notEmpty: {
message: 'Ce champs ne peut pas être vide.'
},
regexp: {
regexp: /^[0-9]+$/,
message: 'Ce champs nécessite une valeur numérique entière.'
}
}
},
venue_status: {
validators: {
notEmpty: {
message: 'Le status doit être défini.'
}
}
},
venue_location: {
validators: {
notEmpty: {
message: 'La localisation doit être définie.'
}
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
我的问题是我的验证步骤运行良好.虽然没有提交表单,所以我尝试将此警报测试添加到调试中.警报也没有出现,这似乎表明commitHelper未被触发.我现在很失落.
小智 7
看来你正在使用旧版本的插件.submitHandler根据升级到v0.5.0指南,从v0.5.0开始,插件将删除选项.请改用success.form.bv事件处理程序.
您可以尝试以下代码:
$('#editForm')
.bootstrapValidator(options)
.on('success.form.bv', function(e) {
e.preventDefault(); // Prevent the form from submitting
alert('I am going to do other things');
// ... Do whatever you want
// If you want to submit the form, use the defaultSubmit() method
// http://bootstrapvalidator.com/api/#default-submit
$('#editForm').bootstrapValidator('defaultSubmit');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2366 次 |
| 最近记录: |