Monday 15 June 2015

scala - How to create multiple custom fields in Play Framework? -


I am trying to create many custom fields

Use as a reference.

After creating MyHelpers

  Object MyHelpers {//} Importing it to '.f' I at my  .scala.html    / I>     east>  @import MyHelpers._   

Then when I do, then magical

  @inputText (myForm ("username"))   

This is my constructor using MyHelpers

but how do I create many constructors, so I can create different input types like:

How do I implement it?

  @inputText (myForm ("username")) @inputDate (myForm ("birth"))   

p> First of all, For some time reading books and articles and loads of things about Scala, but some are barely coded). I am sorry for such a question, but scalar makes learning difficult to play, it seems that you need to master before Scala, so that you can consolidate play or understand how it is made. Documentation does not help a lot in these cases.

Another way to do this is that in many fields a scale object (a separate file) And then import this object into your thoughts. The rest will be easy to follow.

First: Create a scene for the field you want to create. Let's call it textinputgroup.scala.html

This will contain the code

  @ (element: assistant filename, text: string) & lt; Div class = "form-group input-group if (@ elements.hasErrors) {error}" & gt; & Lt; Span class = "input-group-addon" & gt; @ Text & lt; / Span & gt; @ Elements.input & lt; Span class = "errors" & gt; @ Elements.errors.mkString (",") & lt; / Span & gt; & Lt; / Div & gt;   

Then: Create your object helper, let's call it bootstrap.scala and inside it, enter the field you want to create. (You can put textinput.scala.html in the same folder under bootstrap.scala and 'View' directory)

  Import package view views.html.helper._ Object Bootstrap {built-in VAL Address Unit = New Field Constructor {FEFil (Element: Field Elements) = TextInput Group (Element, "@")} Built-in Val Password Input Group = New Field Constructor {Diff Apply (Element: Field Elements) = TextInput Group (element, "*") }}   

And finally: Import and use this object in your thoughts.

  @ (Signin: Form [forms.Signin]) * * Enter your real form definition * / @import assistant ._ @import views.bootstrap._ / * Inside the body * / @ Helper.form (action = routes.Auth.submit ()) {@inputText (signin ("email" ("password"), 'square - & gt; "form-control",' placeholder - & gt; "email Input password (signin ("password"), 'square - & gt;,' placeholder - & gt; "password") (passwordInput group, interact [lang]) & lt ; Button class = "BTN BTN-default" type = "submit Please sign up & raquo; & lt; / button & gt;}   

I use the Bootstrap (Multilevel Configurator) and the Semantic-UI (Semantic Formatter) framework To create many fields, there are some more examples in . See them.

No comments:

Post a Comment