gpt4 book ai didi

templates - 是否可以覆盖表单助手?

转载 作者:行者123 更新时间:2023-12-03 08:22:10 27 4
gpt4 key购买 nike

使用文档,我可以为我的领域的布局设置我自己的助手,但我也想个性化一些由 play 给出的领域。

主要原因是 Twitter Bootstrap 2,我需要更改(在 checkbox.scala.html 中)

@input(field, args:_*) { (id, name, value, htmlArgs) =>
<input type="checkbox" id="@id" name="@name" value="@boxValue" @(if(value == Some(boxValue)) "checked" else "") @toHtmlArgs(htmlArgs.filterKeys(_ == 'value))>
<span>@args.toMap.get('_text)</span>
}

到 :
<label class="checkbox">
<input type="checkbox" name="@name" id="@id" value="@boxValue" @(if(value == Some(boxValue)) "checked" else "") @toHtmlArgs(htmlArgs.filterKeys(_ == 'value)) />
@args.toMap.get('_text)
</label>

我怎样才能做到这一点 ?
谢谢你的帮助!

最佳答案

我终于这样做了:

我创建了一个包 views.helpers.form,其中包含:

bootstrap.scala.html :

@(elements: helper.FieldElements)

<div class="control-group@if(elements.hasErrors) { error}">
<label class="control-label" for="@elements.id">@elements.label(elements.lang)</label>
<div class="controls">
@elements.input
@elements.infos(elements.lang).map { info =>
<span class="help-inline">@info</span>
}
@elements.errors(elements.lang).map { error =>
<span class="help-block">@error</span>
}
</div>

checkbox.scala.html :
@**
* Generate an HTML input checkbox.
*
* Example:
* {{{
* @checkbox(field = myForm("done"))
* }}}
*
* @param field The form field.
* @param args Set of extra HTML attributes ('''id''' and '''label''' are 2 special arguments).
* @param handler The field constructor.
*@
@(field: play.api.data.Field, args: (Symbol,Any)*)(implicit handler: helper.FieldConstructor, lang: play.api.i18n.Lang)

@boxValue = @{ args.toMap.get('value).getOrElse("true") }

@helper.input(field, args:_*) { (id, name, value, htmlArgs) =>
<label class="checkbox">
<input type="checkbox" id="@id" name="@name" value="@boxValue" @(if(value == Some(boxValue)) "checked" else "") @toHtmlArgs(htmlArgs.filterKeys(_ == 'value))>
@args.toMap.get('_text)
</label>


div>
</div>

在我的模板中,我所要做的就是:
@import helper.{FieldConstructor, inputText, inputPassword} @** Import the original helpers *@
@import helpers.form.checkbox @** Import my helpers *@
@implicitField = @{ FieldConstructor(helpers.form.bootstrap.f) }

瞧!有用!

关于templates - 是否可以覆盖表单助手?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10206961/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com