有没有一种简单的方法可以在表单顶部而不是每个字段上方对表单错误进行分组?
这是我的 Scala 模板:
@(registrationForm: Form[User])
@implicitField = @{ FieldConstructor(views.html.helper.twitterBootstrap2.twitterBootstrap2FieldConstructor.f) }
@import helper._
@helper.form(action = routes.Registration.index) {
<fieldset>
@if(registrationForm.hasGlobalErrors) {
<div class="alert alert-error">
<a class="close" data-dismiss="alert">×</a>
@registrationForm.globalError.message
</div>
}
<legend>Register</legend>
@inputText(
registrationForm("firstName"),
'_label -> "First Name",
'_showConstraints -> false,
'_showErrors -> true,
'_error -> registrationForm.error("firstName")
)
@inputText(
registrationForm("lastName"),
'_label -> "Last Name",
'_showConstraints -> false,
'_showErrors -> true,
'_error -> registrationForm.error("lastName")
)
@inputText(
registrationForm("emailAddress"),
'_label -> "Email Address",
'_showConstraints -> false,
'_showErrors -> true,
'_error -> registrationForm.error("emailAddress")
)
@inputPassword(
registrationForm("password"),
'_label -> "Password",
'_showConstraints -> false,
'_showErrors -> true,
'_error -> registrationForm.error("password")
)
@inputPassword(
registrationForm("password"),
'_label -> "Confirm Password",
'_showConstraints -> false,
'_showErrors -> true,
'_error -> registrationForm.error("password")
)
</fieldset>
<button type="submit" class="btn">Register</button>
}
我有一个自定义验证,我正在检查唯一的电子邮件地址,并基于该验证,我在全局错误中添加了一个错误。我希望将任何其他错误(由于验证其他字段而引发)与表单顶部的此错误组合在一起。有什么建议么?