所以我的简单表单定义为:
val loginForm = Form(
mapping(
"email" -> email,
"password" -> nonEmptyText(minLength = 8, maxLength = 24)
)(UserLogin.apply)(UserLogin.unapply)
)
我的观点:
@b4.inline.form(routes.UserController.loginPage()) { implicit ifc =>
@b4.email( form("email"), '_hiddenLabel -> "Email", 'placeholder -> "your email address")
@b4.password( form("password"), '_hiddenLabel -> "Password", 'placeholder -> "your password")
@b4.submit('class -> "btn btn-light btn-outline-dark"){ Login }
}
显然,我的密码字段是在前端验证的,但不是在电子邮件中验证的。是否有一种规范的方法来强制执行前端验证期间所需的电子邮件?
它在前端进行验证,但前提是它不为空。
您需要将字段明确标记为"必需":
@b4.email( form("email"), '_hiddenLabel -> "Email", 'placeholder -> "your email address", 'required -> true)