这不能太罕见。我想将不在我的表单中的“fullPathAndFileName”值放入验证器。
在我的一个控制器中,我有一个文件重命名操作:
def renameAction(fullPathAndFileName: String) = Action { implicit request =>
val newRenameForm = renameForm.bindFromRequest()
newRenameForm.fold(
hasErrors = { form =>
Redirect(routes.TestApp.renderFormAction(fullPathAndFileName)).flashing("error" -> "New filename must be unused and cannot be empty.")
},
success = { newFileName =>
...
这是我的验证器:
private val renameForm: Form[String] = Form("newFileName" -> nonEmptyText.verifying({txt => dupeNotFound(txt)}))
private def dupeNotFound(newFileName: String) = { !Asset.findAsset(replaceFileNameOfAsset(fullPathAndFileName, newFileName)) }
所以这段代码不会编译,因为 fullPathAndFileName 没有定义。如何让验证器使用该值?