2012-10-17 3 views
3

양식에 문제가 있습니다.보기에 오류가 제대로 표시되지 않을 수 있습니다. 유효성 검사가 정상적으로 작동합니다.프레임 워크 2.0 스칼라 양식 오류 처리

암호가 일치하지 않을 때 이전 암호가 틀렸을 때 입력란 아래에 오류 메시지가 표시되는데, 암호가 일치하지 않으면 오류가 어디에도 나타나지 않습니다. 보기에서

: 나는 몇 가지 디버깅을 할 경우

내가 데이터를 얻을 수 @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"> 
    } 
+0

... 적절한 방법으로 다음을 표시 할 수 있지만, 당신은 어떻게 당신의 형태로'user.id'을받을 수 있나요? –

+0

나는 https://github.com/t2v/play20-auth의 모듈을 사용하며 authorizedAction이라는 메서드가 있으며 사용자에게 제공됩니다. – mapek

+0

감사합니다. –

답변

1

첫째. views.html.helper.inputPassword에서 살펴보고과 같이 사용 :

@helper.inputPassword(field = pass_form("old_password")) 

암호가 일치하지 않는 이유 오류가 표시되지 않습니다은 양식 자체에 아닌 특정 바인딩 오류가 있음이다 들. 양식의 errors 필드를 확인해야합니다. 그러면 Seq[FormError]이 표시됩니다. 그런 다음 그것은 덤프 질문 할 수있다

안부

+0

Thx 도움말이지만 inputPassword가 이상하게 작동합니다. 비밀번호 업데이트가 실패한 경우 채워진 값이있는 양식이 표시됩니다. 해결 방법 : @ helper.input (pass_form ("old_password"), '_ 오류 -> pass_form ("old_password") 오류) – mapek