我有一个从以前的表单中填写的输入字段(因此输入在第二页上设置为禁用),然后我们收到 null
作为该值。这有效:
<input type="text" class="boxtpl" name="${field.name}" value="${user?.email}">
但这不是:
<input type="text" class="boxtpl" name="${field.name}" value="${user?.email}" disabled="disabled">
为什么这似乎打破了框架?
最佳答案
禁用控件不应该实际上与表单一起提交,因此您所看到的实际上是正常行为。根据HTML form specification :
When set, the disabled attribute has the following effects on an element:
- Disabled controls do not receive focus.
- Disabled controls are skipped in tabbing navigation.
- Disabled controls cannot be successful.
可以找到successful
的定义in the same document .说 Play 是因为这个坏了有点荒谬。
如果您希望有一个用户无法编辑的表单字段,但在提交表单时仍应将其发送,您可以使用 read-only属性,或使用 JavaScript 来禁止用户输入。
更新:正如评论中指出的,以下几点也可能提供解决方案:
- 有可能 Play 仍将禁用控件的表单值保留在请求对象中,只是不绑定(bind)它们(因此您可以在需要时从请求中检索它们)
- 使用隐藏字段来保留表单值,以防您仍想提交该值,但不希望用户看到该控件
关于html - playframework,输入禁用中断 Play 传递值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9187516/