【发布时间】:2012-10-18 07:12:57
【问题描述】:
我的表单有问题,问题是我无法正确显示错误(我认为是这样)。验证工作正常。
当旧密码不正确时,输入框下方会显示错误消息,而当密码不匹配时,错误不会出现在任何地方。
如果我进行一些调试,我会得到数据:
从视图中:
@pass_form("password").errors
我明白了:
FormError(password,Passwords dont match,WrappedArray())
所以我的问题是如何在视图中修复表单或代码,以正确打印该错误。
Form(
mapping(
"old_password" -> text.verifying(Messages("forms.password.old.mismatch"),
password => User.correct_?(user.id, password)),
"password" -> tuple(
"new" -> text(minLength = conf.getInt("password.length.min").get),
"confirm" -> text).verifying(Messages("forms.password.new.mismatch"),
passwords => passwords._1 == passwords._2)
)
((_, password) => password._1)((_) => Some(("", ("", ""))))
)
在我看来:
@helper.form(action = routes.UserController.submitPassword) {
@helper.input(pass_form("old_password")) { (id, name, value, args) =>
<input type="password" name="@name" id="@id" @toHtmlArgs(args)>
}
@helper.input(pass_form("password.new")) { (id, name, value, args) =>
<input type="password" name="@name" id="@id" @toHtmlArgs(args)>
}
@helper.input(pass_form("password.confirm")) { (id, name, value, args) =>
<input type="password" name="@name" id="@id" @toHtmlArgs(args)>
}
<input type="submit" value="Set">
}
【问题讨论】:
-
这可能是一个转储问题,但您如何在表单中获得
user.id? -
我使用来自github.com/t2v/play20-auth 的模块,并且有一个名为authorizedAction 的方法,它给了我一个用户。
-
谢谢,我会检查的。
标签: forms scala playframework-2.0