玩框架,输入禁用打破传递价值? [英] playframework, input disabled breaks play from passing the value?

查看:97
本文介绍了玩框架,输入禁用打破传递价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由前一个表单填充的输入字段(因此输入在第二个页面上被设置为禁用),然后我们收到 null 作为值。这是有效的:

 < input type =textclass =boxtplname =$ {field.name}值= $ {?用户.email} > 

但这不是:

 < input type =textclass =boxtplname =$ {field.name}value =$ {user?.email}disabled =disabled> 

有没有理由让这个框架破裂?

解决方案

禁用的控件不应该 实际上与表单一起提交,所以您看到的实际上是正常行为。根据 HTML表单规范


设置时,disabled属性对元素具有以下效果:




  • 禁用的控件无法获得焦点。

  • 禁用的控件在标签导航中跳过。 禁用的控件无法成功。


成功的定义可以在同一文档中找到 。如果你想拥有一个用户不能编辑的表单字段,而它仍然应该被发送表单已提交,则可以使用只读属性,或者使用JavaScript来禁止用户输入。

更新:正如评论中指出的,以下几点也可能会提供解决方案:


  • Play可能仍然在请求对象中保留被禁用的控件的表单值,并且不会绑定它们(所以你如果需要,可以从请求中检索它们)

  • 使用隐藏字段保留表单值,以防您仍想提交值但不希望用户看到控制


I have an input field that is filled in from a previous form(so the input is set to disabled on the second page) and we receive null for the value then. This works:

<input type="text" class="boxtpl" name="${field.name}" value="${user?.email}">

but this doesn't:

<input type="text" class="boxtpl" name="${field.name}" value="${user?.email}" disabled="disabled">

Is there a reason why this seems to break the framework?

解决方案

Disabled controls shouldn't actually be submitted with the form, so what you're seeing is in fact normal behaviour. According to the 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.

The definition of successful can be found in the same document. It's a bit nonsensical to suggest that Play is broken because of this.

If you want to have a form field that user cannot edit while it should still be sent along when the form is submitted, you can use the read-only attribute, or use JavaScript to disallow user input.

Update: as pointed out in the comments, the following points may also offer a solution:

  • It's possible that Play still keeps the disabled control's form values in the request object, and just doesn't bind them (so you could retrieve them from the request if needed)
  • Use a hidden field to keep the form value in case you still want to submit the value, but do not want the user(s) to see the control

这篇关于玩框架,输入禁用打破传递价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆