基于 Orbeon 中重复部分中迭代控件动态值的条件

Conditions based on the dynamic values of iterated controls in repeat section in Orbeon

我在重复部分有一个复选框。它只能在迭代中勾选一次。一旦在重复部分中勾选,其余部分必须是只读的。例如:"Once Make him primary applicant" 被选中,然后其他(上一个和下一个)迭代中的复选框必须被禁用或隐藏或只读为空值。请帮助我如何实现这一目标。

<xh:html xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:ev="http://www.w3.org/2001/xml-events"
     xmlns:xi="http://www.w3.org/2001/XInclude"
     xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
     xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
     xmlns:exf="http://www.exforms.org/exf/1-0"
     xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
     xmlns:saxon="http://saxon.sf.net/"
     xmlns:sql="http://orbeon.org/oxf/xml/sql"
     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
     xmlns:fb="http://orbeon.org/oxf/xml/form-builder">
<xh:head>
    <xh:title>Untitled Form</xh:title>
    <xf:model id="fr-form-model" xxf:expose-xpath-types="true">

        <!-- Main instance -->
        <xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
            <form>

                <section-1>
                    <section-1-iteration>
                        <surname/>
                        <checkbox>false</checkbox>
                    </section-1-iteration>
                </section-1>
            </form>
        </xf:instance>

        <!-- Bindings -->
        <xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">

            <xf:bind id="section-1-bind" ref="section-1" name="section-1">
                <xf:bind id="section-1-iteration-bind" ref="section-1-iteration"
                         name="section-1-iteration">
                    <xf:bind id="surname-bind" ref="surname" name="surname" xxf:whitespace="trim"/>
                    <xf:bind id="checkbox-bind" ref="checkbox" name="checkbox" type="xf:boolean"
                             readonly="(../checkbox)"/>
                </xf:bind>
            </xf:bind>
        </xf:bind>

        <!-- Metadata -->
        <xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
            <metadata>
                <application-name>a</application-name>
                <form-name>a</form-name>
                <title xml:lang="en">Untitled Form</title>
                <description xml:lang="en"/>
                <singleton>false</singleton>
            </metadata>
        </xf:instance>

        <!-- Attachments -->
        <xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
            <attachments>
                <css mediatype="text/css" filename="" size=""/>
                <pdf mediatype="application/pdf" filename="" size=""/>
            </attachments>
        </xf:instance>

        <!-- All form resources -->
        <!-- Don't make readonly by default in case a service modifies the resources -->
        <xf:instance id="fr-form-resources" xxf:readonly="false" xxf:exclude-result-prefixes="#all">
            <resources>
                <resource xml:lang="en">
                    <surname>
                        <label>Full Name</label>
                        <hint/>
                    </surname>
                    <checkbox>
                        <label>Make him primary applicant</label>
                        <hint/>
                    </checkbox>

                    <section-1>
                        <label>Caregiver</label>
                    </section-1>



                </resource>
            </resources>
        </xf:instance>

        <xf:instance xxf:readonly="true" id="section-1-template" xxf:exclude-result-prefixes="#all">
            <section-1-iteration>
                <surname/>
                <checkbox>false</checkbox>
            </section-1-iteration>
        </xf:instance>

    </xf:model>
</xh:head>
<xh:body>
    <fr:view>
        <fr:body xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:p="http://www.orbeon.com/oxf/pipeline"
                 xmlns:oxf="http://www.orbeon.com/oxf/processors">

            <fr:section id="section-1-section" bind="section-1-bind" repeat="content" min="1"
                        template="instance('section-1-template')"
                        apply-defaults="true"
                        fb:initial-iterations="first">
                <xf:label ref="$form-resources/section-1/label"/>
                <fr:grid id="grid-2-grid">
                    <fr:c x="1" y="1" w="12">
                        <xf:input id="surname-control" bind="surname-bind">
                            <xf:label ref="$form-resources/surname/label"/>
                            <xf:hint ref="$form-resources/surname/hint"/>
                            <xf:alert ref="$fr-resources/detail/labels/alert"/>


                        </xf:input>
                    </fr:c>
                    <fr:c x="1" y="2" w="12">
                        <fr:checkbox-input xmlns="http://orbeon.org/oxf/xml/form-builder"
                                           xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
                                           id="checkbox-control"
                                           bind="checkbox-bind">
                            <xf:label ref="$form-resources/checkbox/label"/>
                            <xf:hint ref="$form-resources/checkbox/hint"/>
                            <xf:alert ref="$fr-resources/detail/labels/alert"/>


                        </fr:checkbox-input>
                    </fr:c>
                </fr:grid>
            </fr:section>
        </fr:body>
    </fr:view>
</xh:body>

假设您将 Single Checkbox 字段命名为 my-checkbox,那么您可以使用以下验证 XPath 表达式:

count(//my-checkbox[string() = 'true']) <= 1 or
string() != 'true'

用这个表达式,如果你选中了多个复选框,那么所有选中的复选框都会被标记为无效,从而通知用户他们必须更改他们的选择,并防止数据被保存或提交(如果你确实不希望保存或提交无效数据)。

您可能还想添加自定义警报消息,例如 "you can't select more than one primary applicant",以便用户了解问题所在。