2

I have select control which allows to select more than one value.

As and when i select values in that control, it adds the value into same node with a space.

Is it possible to create/delete a new/existing node when we select and deselect.

4

2 回答 2

2

XForms 具有xforms:copy元素,理论上您可以在项集中使用它,并且可能对您有用,但我不知道目前是否有任何 XForms 实现支持这一点。Orbeon Forms 没有。

菲尔的回答是一个可能的方向。另一种选择是仍然使用事件xforms:select/select1并对xforms-select/xforms-deselect事件做出反应以插入/删除节点。以下适用于 Orbeon:

<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
         xmlns:xf="http://www.w3.org/2002/xforms"
         xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
         xmlns:ev="http://www.w3.org/2001/xml-events">
    <xh:head>
        <xf:model>
            <xf:instance>
                <items selection=""/>
            </xf:instance>
        </xf:model>
    </xh:head>
    <xh:body>
        <xf:select1 ref="@selection">
            <xf:item>
                <xf:label>One</xf:label>
                <xf:value>one</xf:value>
            </xf:item>
            <xf:item>
                <xf:label>Two</xf:label>
                <xf:value>two</xf:value>
            </xf:item>

            <xf:insert ev:event="xforms-select" context="instance()" ref="*" origin="xxf:element(event('xxf:item-value'))"/>
            <xf:delete ev:event="xforms-deselect" context="instance()" ref="*[name() = event('xxf:item-value')]"/>

        </xf:select1>
    </xh:body>
</xh:html>
于 2011-02-21T18:41:59.663 回答
0

select元素与您的要求不匹配,因为它只有一个节点绑定。我不会尝试以这种方式颠覆控件的语义,而是使用带有和动作repeattrigger元素,使用 CSS 设置样式,以提供多选控件的外观。insertdelete

您的问题没有提到数据的格式,但假设实例数据如下:

<xf:instance id="options">
    <options xmlns="">
        <option selected="false">
            <first />
        </option>
        <option selected="false">
            <second />
        </option>
        <option selected="false">
            <third />
        </option>
        <option selected="false">
            <fourth />
        </option>
        <option selected="false">
            <fifth />
        </option>
    </options>
</xf:instance>

<xf:instance id="results">
    <results xmlns="" />
</xf:instance>

然后,您应该能够通过以下方式获得您想要的行为(未经测试):

<xf:repeat id="repeat" nodeset="instance('options')/option">
    <xf:trigger appearance="minimal">
        <xf:label>
            <xf:output value="name(*)" />
        </xf:label>

        <xf:action ev:event="DOMActivate" if="@selected = 'false'">
            <xf:setvalue ref="@selected" value="'true'" />
            <xf:insert
             origin="instance('options')/option[index('repeat')]/*"
             context="instance('results')"
             nodeset="*"
             at="count(../*)"
             position="after"
            />
        </xf:action>

        <xf:action ev:event="DOMActivate" if="@selected = 'true'">
            <xf:setvalue ref="@selected" value="'false'" />
            <xf:delete nodeset="instance('results')/*[name(.) = name(current()/*)]" />
        </xf:action>
    </xf:trigger>
</xf:repeat>
于 2011-02-20T13:59:21.660 回答