问题描述
我正在将scala模板与输入助手一起使用.
I am using scala template with input helper.
我使用的class属性将样式应用于<input>
标记.
The class attribute which i use applies style for the <input>
tag.
如何将特定的样式应用于生成的<label>
标签?
How do i apply the style specific to the generated <label>
tag?
@inputText(orderItem("item1"),'_label -> "Product*",'_class -> "tinytfss")
预先感谢您的支持.马诺伊
Thanks in advance for your support. Manoj
推荐答案
您可以尝试放弃内置字段构造函数,而改为编写自己的.以下模板接受用于控制标签样式的自定义参数:
You could try ditching the built-in field constructors and instead write your own. The following template accepts a custom argument that controls the styling of the label:
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 whichever built-in one you were using before:
app/views/form.scala.html
....
@* implicitFieldConstructor = @{ FieldConstructor(twitterBootstrapInput.f) } *@
@implicitField = @{ FieldConstructor(_my_field_constructor.f) }
....
在调用helper函数创建输入文本字段时,您现在可以传递一个自定义的_label_class
参数,模板将使用该参数:
When calling the helper function to create a input text field, you can now pass in a custom _label_class
argument that the template will pick up:
app/views/form.scala.html
@inputText(orderItem("item1"), '_label -> "Product", '_label_class -> "red", '_class -> "tinytfss")
这篇关于Scala模板将样式应用于inputText的标签[播放2 HTML5 helper标签]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!