orbeon

Why is it that using xxforms-value-changed makes my hidden controls relevant?


I want an xforms:insert to occur following a hidden value change. I've set up an instance (temp-instance) to hold the value I want to observe for an xxforms-value-changed event. The event actions an insert into the destination-instance. Also on the form I have a 'hidden' control with relevance set to false(). Subsequent to the insert occurring the relevance flag is ignored. This doesn't appear to occur with other actions being triggered (such as an xforms:setvalue).

Is this a bug?

See FR example below which updates the temp-instance with the content of the 'input' control.

<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">
            <form>
                <section-1>
                    <input/>
                    <hidden>Output</hidden>
                </section-1>
            </form>
        </xf:instance>

        <!-- Temporary instance -->
        <xf:instance id="temp-instance">
            <temp>
                <copy/>
            </temp>
        </xf:instance>            

        <!-- Template instance -->
        <xf:instance id="template-instance">
            <template>
                <extra/>
            </template>
        </xf:instance>

        <!-- Destination instance -->
        <xf:instance id="destination-instance">
            <destination/>
        </xf:instance>

        <!-- Bindings -->
        <xf:bind xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel" id="fr-form-binds"
                 ref="instance('fr-form-instance')">
            <xf:bind id="section-1-bind" name="section-1" ref="section-1">
                <xf:bind id="input-bind" name="input" ref="input"/>
                <xf:bind id="hidden-bind" ref="hidden" name="hidden" relevant="false()"/>
            </xf:bind>
        </xf:bind>

        <xf:bind xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel" id="temp-binds"
                 ref="instance('temp-instance')">
                     <xf:bind id="copy-bind" name="copy" ref="copy" calculate="$input"/>
        </xf:bind>

        <!-- Metadata -->
        <xf:instance xxf:readonly="true" id="fr-form-metadata">
            <metadata>
                <application-name>test</application-name>
                <form-name>example</form-name>
                <title xml:lang="en">Untitled Form</title>
                <description xml:lang="en"/>
            </metadata>
        </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">
            <resources>
                <resource xml:lang="en">
                    <section-1>
                        <label>Section</label>
                    </section-1>
                    <input>
                        <label>Input</label>
                        <hint/>                      
                    </input>
                    <hidden>
                        <label>Hidden</label>
                        <hint/>
                    </hidden>
                </resource>
            </resources>
        </xf:instance>

        <xf:action id="insert-extra-binding">
            <xf:action ev:event="xxforms-value-changed" ev:observer="temp-instance" if="true()">
                <xf:insert context="instance('destination-instance')"
                           origin="instance('template-instance')"/>
            </xf:action>
        </xf:action>
    </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"
                 xmlns:oxf="http://www.orbeon.com/oxf/processors"
                 xmlns:p="http://www.orbeon.com/oxf/pipeline">
            <fr:section id="section-1-control" bind="section-1-bind">
                <xf:label ref="$form-resources/section-1/label"/>
                <fr:grid>
                    <xh:tr>
                        <xh:td>
                            <xf:input id="input-control" bind="input-bind">
                                <xf:label ref="$form-resources/input/label"/>
                                <xf:hint ref="$form-resources/input/hint"/>
                                <xf:alert ref="$fr-resources/detail/labels/alert"/>
                            </xf:input>
                        </xh:td>
                        <xh:td>
                            <xf:output id="hidden-control" bind="hidden-bind">
                                <xf:label ref="$form-resources/hidden/label"/>
                                <xf:hint ref="$form-resources/hidden/hint"/>
                                <xf:alert ref="$fr-resources/detail/labels/alert"/>
                            </xf:output>
                        </xh:td>
                    </xh:tr>
                </fr:grid>
            </fr:section>
        </fr:body>
    </fr:view>
</xh:body>


Solution

  • I just tried your example and I do see that it seems to behave a bit curiously!

    I reproduce this with a simpler example:

    <xh:html
            xmlns:ev="http://www.w3.org/2001/xml-events"
            xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
            xmlns:xf="http://www.w3.org/2002/xforms"
            xmlns:xh="http://www.w3.org/1999/xhtml"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:xxf="http://orbeon.org/oxf/xml/xforms">
        <xh:head>
            <xf:model>
                <xf:instance id="instance">
                    <hidden>I am supposed to be hidden!</hidden>
                </xf:instance>
    
                <xf:bind ref="instance()" relevant="false()"/>
    
                <xf:instance id="copy-instance">
                    <copy/>
                </xf:instance>
    
                 <xf:bind ref="instance('copy-instance')" calculate="42"/>
    
                <xf:instance id="destination-instance">
                    <destination/>
                </xf:instance>
    
                <xf:insert
                    event="xxforms-value-changed"
                    observer="copy-instance"
                    context="instance('destination-instance')"
                    origin="xf:element('foo')"/>
    
            </xf:model>
        </xh:head>
        <xh:body>
            <xf:output ref="instance()"/>
        </xh:body>
    </xh:html>
    

    I added an issue:

    https://github.com/orbeon/orbeon-forms/issues/1568

    UPDATE 2024-08-16: This has been fixed as part of #6442.