【问题标题】:orbeon xform repeating element issueorbeon xform重复元素问题
【发布时间】:2012-09-17 21:42:32
【问题描述】:

我正在尝试使用添加按钮在运行/运行时添加一个重复元素。当我单击添加按钮时,我收到错误 “功能索引使用不在范围内的重复 id 'employee-repeat'”。我不确定我是否在表单中正确引用了重复元素。这是完整的 x 来自 .

      `<xhtml:html xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
        xmlns:saxon="http://saxon.sf.net/"
        xmlns:xi="http://www.w3.org/2001/XInclude"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
        xmlns:sql="http://orbeon.org/oxf/xml/sql"
        xmlns:xforms="http://www.w3.org/2002/xforms"
        xmlns:exforms="http://www.exforms.org/exf/1-0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xhtml="http://www.w3.org/1999/xhtml"
        xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
        xmlns:ev="http://www.w3.org/2001/xml-events">
<xhtml:head>
    <xhtml:title>U Form</xhtml:title>
    <xforms:model id="fr-form-model">
       <xforms:instance id="fr-form-instance">
            <form>
                <section-1>
                    <hello/>
                </section-1>
            </form>
        </xforms:instance>


        <xforms:bind id="fr-form-binds" nodeset="instance('fr-form-instance')">
            <xforms:bind id="section-1-bind" nodeset="section-1">
                <xforms:bind id="hello-bind" nodeset="hello" name="hello"/>
            </xforms:bind>
        </xforms:bind>


        <xforms:instance id="fr-form-metadata" xxforms:readonly="true">
            <metadata>
                <application-name>gvhd</application-name>
                <form-name>test</form-name>
                <title xml:lang="en">Untitled Form</title>
                <description xml:lang="en"/>
                <author/>
                <logo mediatype="" filename="" size=""/>
            </metadata>
        </xforms:instance>


        <xforms:instance id="fr-form-attachments">
            <attachments>
                <css mediatype="text/css" filename="" size=""/>
                <pdf mediatype="application/pdf" filename="" size=""/>
            </attachments>
        </xforms:instance>


        <xforms:instance id="fr-form-resources" xxforms:readonly="true">
            <resources>
                <resource xml:lang="en">
                    <section-1>
                        <label>Section1</label>
                        <help/>
                    </section-1>
                    <hello>
                        <label>hello</label>
                        <hint/>
                        <help/>
                        <alert/>
                    </hello>
                </resource>
            </resources>
        </xforms:instance>

        <xforms:instance id="employees-instance">
            <employees>
                <employee>
                    <first-name>Alice</first-name>
                </employee>
                <employee>
                    <first-name>Bob</first-name>
                </employee>
                <employee>
                    <first-name>Marie</first-name>
                </employee>
            </employees>
        </xforms:instance>


        <xforms:instance id="fr-service-request-instance" xxforms:exclude-result-prefixes="#all">
            <request/>
        </xforms:instance>

        <xforms:instance id="fr-service-response-instance" xxforms:exclude-result-prefixes="#all">
            <response/>
        </xforms:instance>

    </xforms:model>
</xhtml:head>
<xhtml:body>
    <fr:view>
        <xforms:label ref="instance('fr-form-metadata')/title"/>
        <fr:body>
            <fr:section id="section-1-section" bind="section-1-bind">
                <xforms:label ref="$form-resources/section-1/label"/>
                <xforms:help ref="$form-resources/section-1/help"/>
                <fr:grid columns="2">
                    <xforms:repeat nodeset="instance('employees-instance')/employee" id="employee-repeat">
                              <xhtml:tr>
                            <xhtml:td>
                                <xforms:output ref="first-name"/>
                            </xhtml:td>
                            <xhtml:td>
                                <xforms:output ref="first-name"/>
                            </xhtml:td>
                        </xhtml:tr>
                                                  </xforms:repeat>
                    <xhtml:tr>
                        <xhtml:td>
                            <xforms:input bind="hello-bind" id="hello-control">
                                <xforms:label ref="$form-resources/hello/label"/>
                                <xforms:hint ref="$form-resources/hello/hint"/>
                                <xforms:help ref="$form-resources/hello/help"/>
                                <xforms:alert ref="$fr-resources/detail/labels/alert"/>
                            </xforms:input>
                        </xhtml:td>
                        <xhtml:td/>
                    </xhtml:tr>
                    <xhtml:tr>
                        <xhtml:td>
                            <xforms:trigger>
                                <xforms:label>Add</xforms:label>
                                <xforms:insert ev:event="DOMActivate" context="instance('fr-form-instance')" nodeset="instance('employees-instance')/employee" at="index('employee-repeat')"
                                               position="after"/>
                            </xforms:trigger>
                        </xhtml:td>
                        <xhtml:td/>
                    </xhtml:tr>
                </fr:grid>
            </fr:section>
        </fr:body>
    </fr:view>
</xhtml:body>

`

【问题讨论】:

    标签: orbeon xforms


    【解决方案1】:

    您的示例似乎适用于最新的 Orbeon Forms 代码。它运行时没有错误,按下 Add 按钮时会添加“Marie Marie”。你试过Orbeon Forms 4.0 M10这个吗?

    (请注意,4.0 M10 是一个里程碑构建,它还不是 4.0 最终版本。)

    【讨论】:

    • 是的,我尝试了 Orbeon 3.9 CE Sandbox 中的代码,效果很好。
    • 我在 dev-post-3.7.1.200910140016 上运行这个
    • @KripalSingh 抱歉,这是一个非常非常旧的版本,恐怕我无法在这里为您提供帮助。如果可能的话,您应该考虑升级 Orbeon Forms。 (而且由于我们越来越接近 4.0 版本,也许您甚至可以使用 4.0 里程碑版本。)
    【解决方案2】:

    我已在 Orbeon Sandbox 中运行此代码,但无法重现上述错误。我几乎没有与未声明的变量相关的错误,一旦我声明了变量,表单就会正常呈现并且我能够添加新行。

    但是,从技术上讲,我看到您在重复循环之外的 Add 触发器中使用了重复索引 index('employee-repeat'),因此您可能遇到了该错误。为了更好地提供帮助,请告诉我您是如何运行这些表单的。

    更新:根据 OP 评论,这里是更新。

    很容易纠正它。你不应该使用index('employee-repeat')

    1. 如果要在最后添加新行使用at=last()

    2. 如果要在第一次添加使用at=1

    3. 如果你想在中间添加(你想要的位置)然后移动 重复中的Add 链接,对于每一行,您将拥有 Add 链接可在所需位置添加新行。

    【讨论】:

    • 我在 orbeon 表单生成器上运行表单。将其另存为新形式并将其作为新形式运行。我知道 at="index('employee-repeat')" 有问题,不知道如何更正。
    • @KripalSingh:嗨,Kripal,我根据您的评论更新了答案。
    【解决方案3】:

    根据原始 XF 1.1 建议 Kaipa M Sarma 先生的陈述是正确的,一旦您决定使用重复控件之外的触发按钮,请提及相应的索引,如 last() 或 index = 1 。否则,如果您需要在中间或任何位置插入,您决定在重复中使用按钮 ..

    【讨论】:

      猜你喜欢
      • 2014-12-26
      • 2016-12-25
      • 1970-01-01
      • 2015-03-17
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      相关资源
      最近更新 更多