【发布时间】:2013-01-10 04:21:23
【问题描述】:
我在模式中有一些以required=true 作为属性的输入字段。这些元素位于<form> 内,但是当按下提交按钮时,当字段留空时,不会显示所需的警告。我使用 Jade 作为模板引擎和 Bootstrap。
编辑:如果我从提交按钮中删除关闭模式的属性,则所需的属性有效。
所以问题是我如何才能延迟模式解雇,直到填写必填字段?
这是模态框上的翡翠:
div#passwordModal.modal.hide.fade
div.modal-header
button.close(type='button', data-dismiss='modal', aria-hidden='true') x
h3 Password Reset
div.modal-body
form.form-horizontal.form-align-center(action='/changePass', method='post', enctype='multipart/form-data')
div.control-group
label.control-label(for='currentpass') Current Password
div.controls
input#currentpass(type='password', name='passOld', placeholder='enter old password', required=true)
div.control-group
label.control-label(for='newpass') New Password
div.controls
input#newpass(type='password', name='passNew', placeholder='enter new password', required=true)
div.control-group
label.control-label(for='newpassconfirm') Confirm
div.controls
input#newpassconfirm(type='password', name='passNew', placeholder='confirm new password', required=true)
div.control-group
button.btn.btn-success.offset3(type='submit', data-dismiss='modal', aria-hidden='true') Change Password
【问题讨论】:
-
在我看来,你不应该在“提交”上关闭模式,只在“取消”上关闭。我通常评估提交响应以了解我是否必须关闭模式(成功)或显示表单错误(验证错误)。 required 属性是 HTML5,不是用 JS 处理的,所以它不能打开一个模式来突出一个无效的字段....
标签: html twitter-bootstrap modal-dialog pug