如何使字段动态只读,即在 xforms-value-changed 事件和其他事件上?
在更改下拉字段中的值时,我想将字段设为只读。据我的编程知识,我们在绑定字段时将字段设置为只读。有什么方法可以根据事件使字段只读?
On changing a value in a dropdown field, I want to make a field read only. As far my programming knowledge, we set a field read-only while binding the field. Is there any way to make a field read only depending on events?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会提出一个不需要显式事件处理程序的解决方案:您可以使用两组控件,一组为只读,另一组可编辑。要在两个集合之间切换,您可以将每个集合放入
xforms:group
中,并使用ref
属性来控制是否显示该组。这是一个引用互斥条件的组的示例。根据
selectedvalue
实例节点的值,将显示其中一组。如果 select1 的项集比 1 或 0 更复杂,则必须调整xforms:group@ref
属性的 XPath。该解决方案的优点是根本不需要事件处理(或者更准确地说,XForms 引擎本身完成事件处理部分;
xforms:group
充当服务器上的“事件侦听器”)。实例值本身)。还可以将此技术与显式事件处理结合起来:使用发出xforms:setvalue ...
的xforms:action ev:event="xforms-value-changed"
> 在由xforms:group@ref
属性观察的节点上。I would propose a solution that doesn't require explicit event handlers: you could use two sets of controls with one set read-only, the other set editable. To toggle between both sets, you can put each of the sets in a
xforms:group
with aref
attribute that controls if the group is displayed or not.Here's an example with groups referencing mutually exclusive conditions. Depending on the value of the
selectedvalue
instance node, one of the groups is displayed. If the select1's itemset is more complex than just 1 or 0, you will have to adapt the XPath of thexforms:group@ref
attributes.This solution has the advantage that event handling isn't required at all (or, more precisely, the XForms engine does the event handling part itself; the
xforms:group
s act as "event listeners" on the instance value themselves). It's also possible to combine this technique with explicit event handling: using anxforms:action ev:event="xforms-value-changed"
that issues axforms:setvalue ...
on the node that's observed by thexforms:group@ref
attributes.