Re-initialize XBL component on xxforms-iteration-moved

纵饮孤独 提交于 2019-12-23 15:17:26

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/4074920/re-initialize-xbl-component-on-xxforms-iteration-moved

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!