Is there any way to avoid that the Orbeon Form Builder does executes the events in the form code?

145 views Asked by At

This question is related to a previous question in Stackoverflow where is suggested the use of events to create relevant dependencies among elements.

An example of the code where I have one section with one question:

<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: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: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:meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
        <xh:title>StackOverflow</xh:title>
        <xf:model id="fr-form-model" xxf:expose-xpath-types="true">
            <xf:instance id="fr-form-metadata" xxf:exclude-result-prefixes="#all" xxf:readonly="true">
                <metadata>
                    <application-name>WebForms</application-name>
                    <form-name>StackOverflow_v1</form-name>
                    <title xml:lang="en">StackOverflow</title>
                    <description xml:lang="en">Version: 1. Modification date: 2015-06-10 10:18:18. Publication date: 2015-06-10 10:18:18.</description>
                </metadata>
            </xf:instance>
            <xf:instance id="fr-form-instance">
                <form>
                    <Category>
                        <Question/>
                    </Category>
                </form>
            </xf:instance>
            <xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
                <xf:bind id="Category-bind" name="Category" ref="/form/Category">
                    <xf:bind id="Question-bind" name="Question" ref="Question" required="true()"/>
                </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>
                            <label><![CDATA[Category]]></label>
                            <hint/>
                            <alert/>
                            <Question>
                                <label><![CDATA[Question]]></label>
                                <hint/>
                                <alert/>
                                <item>
                                    <label><![CDATA[Answer]]></label>
                                    <hint/>
                                    <value><![CDATA[Answer]]></value>
                                </item>
                                <item>
                                    <label><![CDATA[Answer2]]></label>
                                    <hint/>
                                    <value><![CDATA[Answer2]]></value>
                                </item>
                            </Question>
                        </Category>
                    </resource>
                </resources>
            </xf:instance>
            <xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
                <request/>
            </xf:instance>
            <xf:instance id="fr-service-response-instance" xxf:exclude-result-prefixes="#all">
                <response/>
            </xf:instance>
            <!-- Keep track of visible/hidden status -->
            <xf:instance id="visible">
                <var>
                    <Category>0</Category>
                    <Question>false</Question>
                </var>
            </xf:instance>
            <!-- Change the visibility status for 'Question2'. -->
            <xf:setvalue event="xforms-enabled" observer="Question-control" ref="instance('visible')/Question" value="'true'"/>
            <xf:setvalue event="xforms-disabled" observer="Question-control" ref="instance('visible')/Question" value="'false'"/>
            <!-- Update category showed elements count for 'Question2'. -->
            <xf:setvalue event="xforms-enabled" observer="Question-control" ref="instance('visible')/Category" value="instance('visible')/Category + 1"/>
            <xf:setvalue event="xforms-disabled" observer="Question-control" ref="instance('visible')/Category" value="instance('visible')/Category - 1"/>
        </xf:model>
    </xh:head>
    <xh:body>
        <fr:view>
            <fr:body xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel" xmlns:oxf="http://www.orbeon.com/oxf/processors"
                     xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xbl="http://www.w3.org/ns/xbl">
                <fr:section bind="Category-bind" class="webforms-element webforms-category" id="Category-control">
                    <xf:label mediatype="text/html" ref="instance('fr-form-resources')/resource/Category/label"/>
                    <xf:hint ref="instance('fr-form-resources')/resource/Category/hint"/>
                    <xf:alert ref="instance('fr-form-resources')/resource/Category/alert"/>
                    <xh:tr>
                        <xh:td>
                            <xf:select1 appearance="full" bind="Question-bind" class="webforms-element webforms-question" id="Question-control">
                                <xf:label mediatype="text/html" ref="instance('fr-form-resources')/resource/Category/Question/label"/>
                                <xf:hint ref="instance('fr-form-resources')/resource/Category/Question/hint"/>
                                <xf:alert ref="instance('fr-form-resources')/resource/Category/Question/alert"/>
                                <xf:itemset class="webforms-element webforms-answer" ref="instance('fr-form-resources')/resource/Category/Question/item">
                                    <xf:label ref="label"/>
                                    <xf:value ref="value"/>
                                    <xf:hint ref="hint"/>
                                </xf:itemset>
                            </xf:select1>
                        </xh:td>
                    </xh:tr>
                </fr:section>
            </fr:body>
        </fr:view>
    </xh:body>
</xh:html>

As commented in the previous post, There are two events to save the status of the question (if it is visible or not) and I have added an extra event to count how many elements are visible in the category. The important piece of code is here:

<xf:instance id="visible">
    <var>
         <Category>0</Category>
         <Question>false</Question>
    </var>
</xf:instance>

If I paste the entire example in Orbeon builder version 4.9, and I open it again with the source editor, the code has change to:

<xf:instance id="visible">
    <var>
         <Category>1</Category>
         <Question>true</Question>
    </var>
</xf:instance>

Seems that the Orbeon Builder runs the events and modify the variable values only by pasting the code and show the result in the designer. Therefore, when save into the database and I publish the form, the final value of this variables is the last one. Specially the counter on category that is increased by one each time I edit the source code!

I assume that this is not a desired behaviour in the Form Builder (but it is in the Form Runner) and therefore, the question is: can I disable the execution on events in the Form Builder?

1

There are 1 answers

0
ebruchez On BEST ANSWER

This turns out to be a regression of Form Builder introduced in Orbeon Forms 4.8. Issue #2261 is now fixed.