如何使字段动态只读,即在 xforms-value-changed 事件和其他事件上?

发布于 2024-12-01 10:56:52 字数 71 浏览 0 评论 0原文

在更改下拉字段中的值时,我想将字段设为只读。据我的编程知识,我们在绑定字段时将字段设置为只读。有什么方法可以根据事件使字段只读?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁许谁一生繁华 2024-12-08 10:56:52

我会提出一个不需要显式事件处理程序的解决方案:您可以使用两组控件,一组为只读,另一组可编辑。要在两个集合之间切换,您可以将每个集合放入 xforms:group 中,并使用 ref 属性来控制是否显示该组。

这是一个引用互斥条件的组的示例。根据 selectedvalue 实例节点的值,将显示其中一组。如果 select1 的项集比 1 或 0 更复杂,则必须调整 xforms:group@ref 属性的 XPath。

<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>

该解决方案的优点是根本不需要事件处理(或者更准确地说,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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文