开发者

How to make a field read only dynamically, ie on xforms-value-changed events and other events?

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. I开发者_如何学Pythons there any way to make a field read only depending on events?


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 a ref 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 the xforms:group@ref attributes.

<xforms:select1 appearance="minimal" ref="instance('main')/path/to/selectedvalue">
...
</xforms:select1>

<xforms:group ref="instance('main')/path/to/selectedvalue eq 1">
    <xforms:input ref="instance('main')/path/to/textinput" />
    <!-- more editable XForms controls, bound to main instance -->
</xforms:group>
<xforms:group ref="instance('main')/path/to/selectedvalue eq 0">
    <xforms:input ref="instance('read-only')/path/to/textinput" />
    <!-- more read-only XForms controls, bound to a read-only instance -->
</xforms:group>

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:groups act as "event listeners" on the instance value themselves). It's also possible to combine this technique with explicit event handling: using an xforms:action ev:event="xforms-value-changed" that issues a xforms:setvalue ... on the node that's observed by the xforms:group@ref attributes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜