Domanda

I am having some problems with repeats in XForms. I need to access to some values of a radio button field that is inside a loop. The scope is to make visible an input text if the radio button has selected an specific value. I want this behaviour for all repetitions (radio button and input text field is inside the loop).

It works fine for one row, but when I add a new row, the code does not work any more.

I copy a simple example to check this behaviour:

<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
     xmlns:ev="http://www.w3.org/2001/xml-events"
     xmlns:exf="http://www.exforms.org/exf/1-0"
     xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
     xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
     xmlns:odt="http://orbeon.org/oxf/xml/datatypes"
     xmlns:oxf="http://www.orbeon.com/oxf/processors"
     xmlns:p="http://www.orbeon.com/oxf/pipeline"
     xmlns:saxon="http://saxon.sf.net/"
     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
     xmlns:sql="http://orbeon.org/oxf/xml/sql"
     xmlns:xf="http://www.w3.org/2002/xforms"
     xmlns:xi="http://www.w3.org/2001/XInclude"
     xmlns:xpl="java:org.orbeon.oxf.pipeline.api.FunctionLibrary"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
     xmlns:xxi="http://orbeon.org/oxf/xml/xinclude">
<xh:head>
    <xh:title>Loop</xh:title>
    <xf:model id="fr-form-model" xxf:expose-xpath-types="true">
        <xf:instance xxf:readonly="true" id="fr-form-metadata">
            <metadata>
                <application-name>DHszw</application-name>
                <form-name>Loop</form-name>
                <title xml:lang="en">Loop</title>
                <description xml:lang="en">Description of the form.</description>
            </metadata>
        </xf:instance>
        <xf:instance id="fr-form-instance">
            <form>
                <category-1>
                    <subcategory-1-1/>
                    <element-1-1-1/>
                    <loop-group-0>
                        <loop-0>
                            <element-1-1-2/>
                            <element-1-1-3/>
                        </loop-0>
                    </loop-group-0>
                    <element-1-1-4/>
                    <element-1-1-5/>
                </category-1>
            </form>
        </xf:instance>
        <xf:bind xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel" id="fr-form-binds"
                 ref="instance('fr-form-instance')">
            <xf:bind id="category-1-bind" name="category-1" ref="category-1">
                <xf:bind id="subcategory-1-1-bind" name="subcategory-1-1" ref="subcategory-1-1"/>
                <xf:bind id="element-1-1-1-bind" name="element-1-1-1" ref="element-1-1-1"/>
                <xf:bind id="group-loop-0-bind" name="group-loop-0-bind" ref="loop-group-0"
                         relevant="($element-1-1-1='yes' )">
                    <xf:bind id="loop-0-bind" name="loop-0" ref="loop-0" relevant="($element-1-1-1='yes' )">
                        <xf:bind id="element-1-1-2-bind" name="element-1-1-2" ref="element-1-1-2"
                                 relevant="($element-1-1-1='yes' )"/>
                        <xf:bind id="element-1-1-3-bind" name="element-1-1-3" ref="element-1-1-3"
                                 relevant="($element-1-1-2='yes' )"/>
                    </xf:bind>
                </xf:bind>
                <xf:bind id="element-1-1-4-bind" name="element-1-1-4" ref="element-1-1-4"
                         relevant="($element-1-1-1='no' ) or ($element-1-1-2='no' )"/>
                <xf:bind id="element-1-1-5-bind" name="element-1-1-5" ref="element-1-1-5"
                         relevant="($element-1-1-1='no' ) or ($element-1-1-2='no' )"/>
            </xf:bind>
        </xf:bind>
        <xf:instance id="fr-form-attachments">
            <attachments>
                <css filename="" mediatype="text/css" size=""/>
                <pdf filename="" mediatype="application/pdf" size=""/>
            </attachments>
        </xf:instance>
        <xf:instance id="fr-form-resources" xxf:readonly="false">
            <resources>
                <resource xml:lang="en">
                    <category-1>
                        <label>LoopCategory</label>
                    </category-1>
                    <subcategory-1-1>
                        <label>&lt;b&gt;BasicSubcategory&lt;/b&gt;&lt;hr&gt;</label>
                        <hint/>
                        <alert/>
                    </subcategory-1-1>
                    <element-1-1-1>
                        <label>Do you want a loop?</label>
                        <hint/>
                        <alert/>
                        <item>
                            <label>yes</label>
                            <value>yes</value>
                        </item>
                        <item>
                            <label>no</label>
                            <value>no</value>
                        </item>
                    </element-1-1-1>
                    <element-1-1-2>
                        <label>Do you want an Input Text?</label>
                        <hint>More</hint>
                        <alert/>
                        <item>
                            <label>yes</label>
                            <value>yes</value>
                        </item>
                        <item>
                            <label>no</label>
                            <value>no</value>
                        </item>
                    </element-1-1-2>
                    <element-1-1-3>
                        <label>Your input text</label>
                        <hint/>
                        <alert/>
                    </element-1-1-3>
                    <element-1-1-4>
                        <label>Why no loop?</label>
                        <hint/>
                        <alert/>
                    </element-1-1-4>
                    <element-1-1-5>
                        <label>End:</label>
                        <hint/>
                        <alert/>
                    </element-1-1-5>
                </resource>
            </resources>
        </xf:instance>
        <xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
            <response/>
        </xf:instance>
        <xf:instance xxf:readonly="true" id="loop-0-template">
            <loop-0>
                <element-1-1-2/>
                <element-1-1-3/>
            </loop-0>
        </xf:instance>
    </xf:model>
</xh:head>
<xh:body>
    <fr:view>
        <fr:body xmlns:xbl="http://www.w3.org/ns/xbl"
                 xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel">
            <fr:section bind="category-1-bind" id="category-1-control">
                <xf:label ref="$form-resources/category-1/label"/>
                <xh:tr>
                    <xh:td>
                        <xf:output bind="subcategory-1-1-bind" id="subcategory-1-1-control">
                            <xf:label mediatype="text/html" ref="$form-resources/subcategory-1-1/label"/>
                            <xf:hint ref="$form-resources/subcategory-1-1/hint"/>
                            <xf:alert ref="$fr-resources/detail/labels/alert"/>
                        </xf:output>
                    </xh:td>
                </xh:tr>
                <xh:tr>
                    <xh:td>
                        <xf:select1 appearance="full" bind="element-1-1-1-bind" id="element-1-1-1-control">
                            <xf:label ref="$form-resources/element-1-1-1/label"/>
                            <xf:hint ref="$form-resources/element-1-1-1/hint"/>
                            <xf:alert ref="$fr-resources/detail/labels/alert"/>
                            <xf:itemset ref="$form-resources/element-1-1-1/item">
                                <xf:label ref="label"/>
                                <xf:value ref="value"/>
                            </xf:itemset>
                        </xf:select1>
                    </xh:td>
                </xh:tr>
                <xf:group bind="group-loop-0-bind" id="group-loop-0-control">
                    <fr:grid bind="loop-0-bind" id="loop-0-control" max="10" min="1"
                             origin="instance('loop-0-template')"
                             repeat="true">
                        <xh:tr>
                            <xh:td>
                                <xf:select1 appearance="full" bind="element-1-1-2-bind" id="element-1-1-2-control">
                                    <xf:label ref="$form-resources/element-1-1-2/label"/>
                                    <xf:hint ref="$form-resources/element-1-1-2/hint"/>
                                    <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                    <xf:itemset ref="$form-resources/element-1-1-2/item">
                                        <xf:label ref="label"/>
                                        <xf:value ref="value"/>
                                    </xf:itemset>
                                </xf:select1>
                            </xh:td>
                        </xh:tr>
                        <xh:tr>
                            <xh:td>
                                <xf:input bind="element-1-1-3-bind" id="element-1-1-3-control">
                                    <xf:label ref="$form-resources/element-1-1-3/label"/>
                                    <xf:hint ref="$form-resources/element-1-1-3/hint"/>
                                    <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                </xf:input>
                            </xh:td>
                        </xh:tr>
                    </fr:grid>
                </xf:group>
                <xh:tr>
                    <xh:td>
                        <xf:input bind="element-1-1-4-bind" id="element-1-1-4-control">
                            <xf:label ref="$form-resources/element-1-1-4/label"/>
                            <xf:hint ref="$form-resources/element-1-1-4/hint"/>
                            <xf:alert ref="$fr-resources/detail/labels/alert"/>
                        </xf:input>
                    </xh:td>
                </xh:tr>
                <xh:tr>
                    <xh:td>
                        <xf:input bind="element-1-1-5-bind" id="element-1-1-5-control">
                            <xf:label ref="$form-resources/element-1-1-5/label"/>
                            <xf:hint ref="$form-resources/element-1-1-5/hint"/>
                            <xf:alert ref="$fr-resources/detail/labels/alert"/>
                        </xf:input>
                    </xh:td>
                </xh:tr>
            </fr:section>
        </fr:body>
    </fr:view>
</xh:body>

If this code is run in a Orbeon server, it works fine until we add a new row in the 'repeat' element. Then the input field disappear (or is not visible) regardless the value selected in the radio button.

I imagine, that adding the copy of the row, probably will have the same element name (or changes the original element name) and causes this issue. But I need to access to the value of the radio button for each row. Is it possible? Is it a known bug? How can achieve this?

È stato utile?

Soluzione

You can use the relative path to the element instead of the bind variable to refer to element values within the repeat, so in your case:

Replace:

($element-1-1-2='yes' )

with

(../element-1-1-2='yes')

See also orbeon calculated fields in a repeat break after first itiration

This won't work outside the repeat; I'm not sure of your intended logic in the second element-1-1-2 condition.

Regards

jez

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top