Form validation and form helper

后端 未结 3 422
旧巷少年郎
旧巷少年郎 2021-01-30 12:00

I still struggle with the form validation and form helpers in Play 2.0. I have this login screen that I use together with the Twitter Bootstrap. So my login form looks like this

3条回答
  •  北海茫月
    2021-01-30 12:34

    The info text comes from @elements.infos.mkString(", "). To show the errors, you should use @elements.errors(elements.lang).mkString(", ") instead.

    The correct parameter to change the infos content would be help (this is a bit inconsistent, you have to read the source to realize this) so if you want to use the built-in bootstrap fields but suppress the infos, you'd pass '_help -> "".

    Edit for #4:

    Here's how you should call your specific checkbox:

    @checkbox(loginForm("remember"), '_label -> Messages("login.remeberme"))(handler = implicitFieldConstructor, implicitly[Lang])

    And yes, @input means there's a template called input.scala.html. It's the basic template for all input helpers.

    To understand why and how this works, you should dive a little deeper into Play 2.0 and Scala (esp. implicit arguments).

提交回复
热议问题