XFORMS 多选选项绑定问题

发布于 2024-10-18 09:34:34 字数 102 浏览 0 评论 0原文

我有一个选择控件,允许选择多个值。

当我在该控件中选择值时,它会将值添加到带有空格的同一节点中。

当我们选择和取消选择时,是否可以创建/删除新的/现有的节点。

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.

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

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

发布评论

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

评论(2

素罗衫 2024-10-25 09:34:34

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

Phil的回答是一个可能的方向。另一种选择是仍然使用 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>

XForms has the xforms:copy element, which you can in theory use in itemsets, and which might have worked for you, but I don't know if any XForms implementation supports this at this time. Orbeon Forms doesn't.

Phil's answer is a possible direction. Another option is to still use xforms:select/select1 and react to the xforms-select/xforms-deselect events to insert/delete nodes. The following works with 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>
智商已欠费 2024-10-25 09:34:34

select 元素不太符合您的要求,因为它只有一个节点绑定。我不会尝试以这种方式颠覆控件的语义,而是使用带有 insertdeletetrigger 元素的 repeat code> actions,使用 CSS 进行样式设置,以提供多选控件的外观。

您的问题没有提到数据的格式,但假设像这样的实例数据:

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

The select element is a poor match for your requirements because it only has a single node binding. Instead of trying to subvert the control's semantics in that way, I would use a repeat of trigger elements with insert and delete actions, styled with CSS in such a way as to provide the appearance of a multi-selection control.

Your question doesn't mention the format of the data, but supposing instance data like this:

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

Then you should be able to get the behaviour you want with something along these lines (not tested):

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