Form validation and form helper

后端 未结 3 463
旧巷少年郎
旧巷少年郎 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:35

    1. Because of this line @elements.infos.mkString(", "). You are displaying the information about the field there. Remove it to don't display the information.
    2. Add this code:

      @if(elements.hasErrors) {
          @elements.infos.mkString(", ") 
      }
      
    3. To set the classname: add this to your Twitter Bootstrap field: class="@elements.args.get('_class). And in your login form add the class parameter, like this: @inputText(loginForm("email"), '_label -> "Email", '_class -> "classname")

    To understand the concept, take a look at the source code: https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/views/helper/defaultFieldConstructor.scala.html

提交回复
热议问题