重新初始化 xxforms-iteration-moved 上的 XBL 组件

发布于 2024-09-30 09:19:13 字数 390 浏览 3 评论 0原文

我有一个 XBL 组件,它在 javascript 中创建一个复选框控件。值是在组件初始化期间在 javascript 中设置的。当不在重复内部使用时,组件运行良好,但当我尝试向上或向下移动行时,在内部重复 XBL 控件不会更改状态。

xxforms-iteration-moved 事件在移动的行上触发,但不会在此移动期间更改位置的行上触发。例如,如果我将第 3 行移动到第 2 行,则 xxforms-iteration-moved 在第 3 行上触发,但我想重新初始化第 2 行中的组件,并且我的状态保存在 javascript 中。

我认为 xxforms-iteration-moved 应该在改变位置的两行上触发?这实际上是涉及两行的交换。请评论。

编辑:我正在使用 Orbeon Form Runner

I have a XBL component which creates a checkbox control in javascript. Value is set in javascript during the component initialization. Component works well when not used inside repeat but inside repeat when I try to move rows up or down XBL control doesn't change the state.

xxforms-iteration-moved event is fired on the row which is moved but doesn't fire on the row which changes position during this move. For instance, if I move row 3 to row 2 then xxforms-iteration-moved is fired on row 3 but I want to reinitialize components in row 2 as well as my state is saved in javascript.

I think xxforms-iteration-moved should be fired on both rows which changed position? This is really a swap which involves both rows. Please comment.

Edit: I am using Orbeon Form Runner

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

嘿嘿嘿 2024-10-07 09:19:13

xxforms-iteration-moved 分派到哪些组件取决于如何定义 xxforms-iteration-moved 。现在,它被分派到移动的迭代内的控件。除了 xxforms-iteration-moved 之外,您可能还需要处理 xforms-enabled 事件。考虑以下示例:您从包含“a、c、d”的列表开始。如果您在“a”之后插入“b”,则新的“b”将获得一个 xforms-enabled,而“c, d”将分别获得一个 xxforms-iteration-moved 。因此,通过对这两个事件做出反应,您应该能够根据需要(重新)初始化您的组件。

<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
      xmlns:xforms="http://www.w3.org/2002/xforms"
      xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
    <xhtml:head>
        <xhtml:title>Iteration moved</xhtml:title>
        <xforms:model>
            <xforms:instance>
                <instance>
                    <letter>a</letter>
                    <letter>c</letter>
                    <letter>d</letter>
                    <letter>e</letter>
                </instance>
            </xforms:instance>
        </xforms:model>
    </xhtml:head>
    <xhtml:body>
        <fr:button>
            <xforms:label>Insert b</xforms:label>
            <xforms:insert ev:event="DOMActivate" nodeset="letter" at="1" position="after" origin="xxforms:element('letter', 'b')"/>
        </fr:button>
        <fr:button>
            <xforms:label>Delete c</xforms:label>
            <xforms:delete ev:event="DOMActivate" nodeset="letter[. = 'c']"/>
        </fr:button>
        <xforms:repeat id="letter-repeat" nodeset="letter">
            <xforms:output id="letter" value=".">
                <xforms:message ev:event="xxforms-iteration-moved" level="modal" value="concat('xxforms-iteration-moved : ', .)"/>
                <xforms:message ev:event="xforms-enabled" level="modal" value="concat('xforms-enabled : ', .)"/>
            </xforms:output>
        </xforms:repeat>
    </xhtml:body>
</xhtml:html>

我应该补充一点,如果您希望您的组件在重复中使用(并且迟早每个组件都会如此),那么现在,由于重复在客户端的工作方式,如果您正在做一些工作来初始化 < 上的组件code>xforms-enabled,您很可能也需要在 xxforms-iteration-moved 上执行此操作。例如,请参阅 这是如何在 fr:button 组件中完成的。

To what components the xxforms-iteration-moved is dispatched is a matter of how xxforms-iteration-moved is defined. Right now, it is dispatched to controls inside iterations that moved. What you might need is to handle the xforms-enabled event, in addition to xxforms-iteration-moved. Consider the following example: you start with a list with "a, c, d". If you insert "b" after "a", then the new "b" gets an xforms-enabled and "c, d" each get a xxforms-iteration-moved. So by reacting to both events, you should be able to (re)initialize your component as necessary.

<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
      xmlns:xforms="http://www.w3.org/2002/xforms"
      xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
    <xhtml:head>
        <xhtml:title>Iteration moved</xhtml:title>
        <xforms:model>
            <xforms:instance>
                <instance>
                    <letter>a</letter>
                    <letter>c</letter>
                    <letter>d</letter>
                    <letter>e</letter>
                </instance>
            </xforms:instance>
        </xforms:model>
    </xhtml:head>
    <xhtml:body>
        <fr:button>
            <xforms:label>Insert b</xforms:label>
            <xforms:insert ev:event="DOMActivate" nodeset="letter" at="1" position="after" origin="xxforms:element('letter', 'b')"/>
        </fr:button>
        <fr:button>
            <xforms:label>Delete c</xforms:label>
            <xforms:delete ev:event="DOMActivate" nodeset="letter[. = 'c']"/>
        </fr:button>
        <xforms:repeat id="letter-repeat" nodeset="letter">
            <xforms:output id="letter" value=".">
                <xforms:message ev:event="xxforms-iteration-moved" level="modal" value="concat('xxforms-iteration-moved : ', .)"/>
                <xforms:message ev:event="xforms-enabled" level="modal" value="concat('xforms-enabled : ', .)"/>
            </xforms:output>
        </xforms:repeat>
    </xhtml:body>
</xhtml:html>

I should add that if you expect your component to be used in a repeat (and sooner or later every component is), right now, because of how repeats work on the client side, if you are doing some work to initialize the component on xforms-enabled, you most likely need to do that as well on xxforms-iteration-moved. For instance, see how this is done in the fr:button component.

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