Scala Template applied to inputText [Play 2 HTML5 helper tag]

I am using a scala template with an input helper.

The class attribute that I use applies the style for the <input> .

How to apply a style specific to the generated <label> ?

 @inputText(orderItem("item1"),'_label -> "Product*",'_class -> "tinytfss") 

Thanks in advance for your support. Manoah

+3
source share
2 answers

You can try pushing through the built-in field constructors and write your own instead. The following template accepts a custom argument that controls label styles:

app / views / _my_field_constructor.scala.html

 @(element: helper.FieldElements) <div class="clearfix @if(element.hasErrors){error}"> <label for="@element.id" class="@element.args.get('_label_class)">@element.label</label> <div class="input"> @element.input </div> </div> 

Now use your new field constructor instead of the one you used earlier:

app / views / form.scala.html

 .... @* implicitFieldConstructor = @{ FieldConstructor(twitterBootstrapInput.f) } *@ @implicitField = @{ FieldConstructor(_my_field_constructor.f) } .... 

When calling a helper function to create an input text field, you can pass the user argument _label_class , which will receive the template:

app / views / form.scala.html

 @inputText(orderItem("item1"), '_label -> "Product", '_label_class -> "red", '_class -> "tinytfss") 
+7
source

I myself ran into this problem, but I was able to solve it without using a custom FieldConstructor. All I did was change my helper line of the form to include the form id and then reference the label for that form in css. For example:

scala template file:

  <style> #new-tenant-form label { font-weight: bold; } </style> . . . @helper.form(routes.Tenants.create(), 'id -> "new-tenant-form") { . . . 
0
source

All Articles