我正在使用带有输入助手的 scala 模板。
我使用的类属性适用于<input>
标签的样式。
如何应用特定于生成<label>
标签的样式?
@inputText(orderItem("item1"),'_label -> "Product*",'_class -> "tinytfss")
预先感谢您的支持。马诺伊
我正在使用带有输入助手的 scala 模板。
我使用的类属性适用于<input>
标签的样式。
如何应用特定于生成<label>
标签的样式?
@inputText(orderItem("item1"),'_label -> "Product*",'_class -> "tinytfss")
预先感谢您的支持。马诺伊
您可以尝试放弃内置的字段构造函数,而是编写自己的. 以下模板接受控制标签样式的自定义参数:
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>
现在使用您的新字段构造函数,而不是您之前使用的任何内置构造函数:
应用程序/视图/form.scala.html
....
@* implicitFieldConstructor = @{ FieldConstructor(twitterBootstrapInput.f) } *@
@implicitField = @{ FieldConstructor(_my_field_constructor.f) }
....
当调用辅助函数来创建输入文本字段时,您现在可以传入_label_class
模板将拾取的自定义参数:
应用程序/视图/form.scala.html
@inputText(orderItem("item1"), '_label -> "Product", '_label_class -> "red", '_class -> "tinytfss")
我自己也遇到了这个问题,但我能够在不使用自定义 FieldConstructor 的情况下解决它。我所做的只是更改我的表单助手行以包含表单 ID,然后在 css 中引用该表单的标签。像这样:
斯卡拉模板文件:
<style>
#new-tenant-form label {
font-weight: bold;
}
</style>
. . .
@helper.form(routes.Tenants.create(), 'id -> "new-tenant-form") {
. . .