orbeon / orbeon-forms

Orbeon Forms is an open source web forms solution. It includes an XForms engine, the Form Builder web-based form editor, and the Form Runner runtime.
http://www.orbeon.com/
GNU Lesser General Public License v2.1
511 stars 220 forks source link

Control cleared upon `xforms-disabled` doesn't recalculate #6370

Open ebruchez opened 3 weeks ago

ebruchez commented 3 weeks ago

+1 from customer

See form:

<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:map="http://www.w3.org/2005/xpath-functions/map"
         xmlns:array="http://www.w3.org/2005/xpath-functions/array"
         xmlns:math="http://www.w3.org/2005/xpath-functions/math"
         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>#6370: Control cleared upon xforms-disabled doesn't recalculate</xh:title>
        <xf:model id="fr-form-model" xxf:expose-xpath-types="true" xxf:analysis.calculate="true">

            <!-- Main instance -->
            <xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
                <form>
                    <section-1>
                        <grid-1>
                            <show>false</show>
                            <control-1/>
                        </grid-1>

                    </section-1>
                </form>
            </xf:instance>

            <!-- Bindings -->
            <xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
                <xf:bind id="section-1-bind" name="section-1" ref="section-1">
                    <xf:bind id="grid-1-bind" ref="grid-1" name="grid-1">
                        <xf:bind id="show-bind" ref="show" name="show" type="xf:boolean"/>
                        <xf:bind id="control-1-bind" ref="control-1" name="control-1" calculate="42"
                                 relevant="$show = true()"
                                 readonly="false()"/>
                    </xf:bind>

                </xf:bind>
            </xf:bind>

            <!-- Metadata -->
            <xf:instance id="fr-form-metadata" xxf:readonly="true" xxf:exclude-result-prefixes="#all">
                <metadata>
                    <application-name>issue</application-name>
                    <form-name>6370</form-name>
                    <title xml:lang="en">#6370: Control cleared upon xforms-disabled doesn't recalculate</title>
                    <description xml:lang="en"/>
                    <created-with-version>2024.1-SNAPSHOT PE</created-with-version>
                    <updated-with-version>2024.1-SNAPSHOT PE</updated-with-version>

                    <library-versions>
                        <orbeon>3</orbeon>
                    </library-versions>

                    <grid-tab-order>default</grid-tab-order>
                    <email>
                        <templates>
                            <template name="default">
                                <headers/>
                                <exclude-from-all-control-values/>
                            </template>
                        </templates>
                        <parameters/>
                    </email>
                </metadata>
            </xf:instance>

            <!-- Attachments -->
            <xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
                <attachments/>
            </xf:instance>

            <!-- All form resources -->
            <xf:instance xxf:readonly="true" id="fr-form-resources" xxf:exclude-result-prefixes="#all">
                <resources>
                    <resource xml:lang="en">
                        <show>
                            <label>Show</label>
                            <hint/>
                        </show>
                        <control-1>
                            <label/>
                            <hint/>
                        </control-1>
                        <section-1>
                            <label/>
                        </section-1>

                    </resource>
                </resources>
            </xf:instance>
            <!-- Custom handler -->
            <xf:setvalue event="xforms-disabled" observer="fr-form-group" ref="event('xxf:binding')"/>
        </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">
                    <fr:grid id="grid-1-grid" bind="grid-1-bind">
                        <fr:c y="1" x="1" w="6">
                            <fr:checkbox-input xmlns="http://orbeon.org/oxf/xml/form-builder"
                                               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                               xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
                                               id="show-control"
                                               bind="show-bind">
                                <xf:label ref="$form-resources/show/label"/>
                                <xf:hint ref="$form-resources/show/hint"/>
                                <xf:alert ref="$fr-resources/detail/labels/alert"/>

                            </fr:checkbox-input>

                            </fr:c>
                        <fr:c y="1" x="7" w="6">
                            <xf:output id="control-1-control" bind="control-1-bind">
                                <xf:label ref="$form-resources/control-1/label"/>
                                <xf:hint ref="$form-resources/control-1/hint"/>
                                <xf:alert ref="$fr-resources/detail/labels/alert"/>

                            </xf:output>
                        </fr:c>
                    </fr:grid>
                </fr:section>
            </fr:body>
        </fr:view>
    </xh:body>
</xh:html>
ebruchez commented 3 weeks ago

This is not a new issue. I repro it on 2023.1-pe, master, and user reported on 2021.1.x (I think).

ebruchez commented 3 weeks ago

Fails in a simple example with xxf:xpath-analysis="true".

<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:xs="http://www.w3.org/2001/XMLSchema">
    <xh:head>
        <xf:model xxf:expose-xpath-types="true" xxf:xpath-analysis="true">
            <xf:instance>
                <_ xmlns="">
                    <show>false</show>
                    <value/>
                </_>
            </xf:instance>
            <xf:bind ref="show" type="xs:boolean"/>
            <xf:bind ref="value" calculate="42" relevant="../show = true()"/>
            <xf:setvalue event="xforms-disabled" observer="value-input" ref="event('xxf:binding')"/>
        </xf:model>
    </xh:head>
    <xh:body>
        <xf:input ref="show">
            <xf:label>Toggle visibility</xf:label>
        </xf:input>
        <xf:input ref="value" id="value-input">
            <xf:label>Value</xf:label>
        </xf:input>
    </xh:body>
</xh:html>