【问题标题】:Default _showConstraints value for the form inputText in views视图中表单 inputText 的默认 _showConstraints 值
【发布时间】:2014-07-05 20:03:21
【问题描述】:

我不想为我的每个视图的 inputText 定义 arg '_showConstraints -> false。

@inputText(taskForm("name"), '_showConstraints -> false )

如何将此值默认为 false ?

我在 ./play/src/main/scala/views/helper/Helpers.scala 中找到了一些关于这个 arg 的东西:

def infos(implicit lang: play.api.i18n.Lang): Seq[String] = {
  args.get('_help).map(m => Seq(m.toString)).getOrElse {
    (if (args.get('_showConstraints) match {
      case Some(false) => false
      case _ => true
    }) {
      field.constraints.map(c => play.api.i18n.Messages(c._1, c._2: _*)) ++
        field.format.map(f => play.api.i18n.Messages(f._1, f._2: _*))
    } else Nil)
  }
}

我是 scala 的新手,如何在我的项目中覆盖 Helpers.scala 的这部分代码?

(PS:我不考虑编辑 ./play/src/main/scala/views/helper/Helpers.scala 作为解决方案)

【问题讨论】:

    标签: playframework-2.0


    【解决方案1】:

    创建您自己的 FieldConstructor(更多信息:http://www.playframework.com/documentation/2.3.x/JavaFormHelpers),并指定类似的内容:

    @if(elements.args.get('_showConstraints).map{ _ == true}.getOrElse(false)) {
        <pre class="help-block">@elements.infos(elements.lang).mkString(", ")</pre>
    }
    

    现在只有在您指定时才会显示约束:

    @helper.inputText(form("name"), '_showConstraints -> true)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-09
      • 1970-01-01
      • 2021-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-23
      • 1970-01-01
      相关资源
      最近更新 更多