【问题标题】:How to get the value from a Form without validating the fields?如何在不验证字段的情况下从表单中获取值?
【发布时间】:2017-02-23 19:43:11
【问题描述】:

我有一个 scala 模板,并且我传递了一个表单实例,其中包含一个填充了我的数据的 Ticket 实例,以便呈现我的页面 ticketForm : Form[Ticket]。但是,我的模板的一部分将List<Object> items 呈现为<ul>,我不想将此列表作为模板上的参数传递,因为我已经将它作为ticket 对象本身的属性。我使用的是ticketForm.get().getItems,但它运行验证并引发异常。

还有其他方法吗?

【问题讨论】:

    标签: java playframework playframework-2.0 playframework-2.5


    【解决方案1】:

    不要使用get,只使用ticketForm('myproperty')

    生成电台组示例:

    https://github.com/playframework/playframework/blob/master/framework/src/play/src/main/scala/views/helper/inputRadioGroup.scala.html

    在这种情况下,如果你想处理一个列表,比如@repeat helper

    @helper.repeat(userForm("emails"), min = 1) { emailField =>
        @helper.inputText(emailField)
    }
    

    这里是repeat helper的实现:

    https://github.com/playframework/playframework/blob/master/framework/src/play/src/main/scala/views/helper/Helpers.scala#L80

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      • 1970-01-01
      • 2019-02-23
      • 2013-01-01
      • 1970-01-01
      • 2019-12-07
      • 1970-01-01
      相关资源
      最近更新 更多