0
votes

I am opening xform page, and directly submit the form, without visiting the form fields. If form has validation errors then it doesn't submit data, BUT it doesn't either show the validations errors in default Error Summary Component. I show a modal dialog, when event "xforms-submit-error" occurs.

The validation errors are controlled by Error Summary Component: From its documentation, we see that "...Error Summary Component...Keeps track of visited controls, and shows error only for those visited while keeping track of all errors..." And this is happening! :-)

So i want if the user tries to submit the form, WITHOUT "visiting" any form field, if there is any validation error, to list the validation errors.

I found in various orbeon related sites/code samples/forums that in order to do this, should make use of "visit-all" action, which will result in marking all controls "visited", so their related error shows!

So tried something like this, but no luck!:

...
   
    <xf:submission id="submit" ...
        ...
        <xf:action ev:event="xforms-submit-error">
            <xf:message level="modal">Oooops!</xf:message>
            <!-- virtual visit all form fields? -->
            <xf:dispatch name="fr-visit-all" targetid="error-summary"/>
            <xf:refresh/>
            <xf:dispatch name="fr-update" targetid="error-summary"/>
        </xf:action>
        ...
    </xf:submission >

    ...
    </xf:model>
</xh:head>
<xh:body>
    <fr:view>
    ...
    
    <xf:trigger id="submit-control" bind="submit-bind">
        <xf:label ref="$form-resources/submit/label" />
        <xf:send ev:event="DOMActivate" submission="submit" />
    </xf:trigger>
    
    ...

How to access default "error-summary"? I didn't add custom error-summary, i want to use the built-in component.

using Orbeon Forms 4.5

1
I checked and Form Runner does dispatch fr-visit-all. This causes the Error Summary to also use the <xxf:setvisited> action to mark all controls as visited. So I am not sure why that doesn't work in your case. Can you try fr-visit-all before submitting? - ebruchez
targetid should be "error-summary", "fr-error-summary-model", something else? - oikonomopo

1 Answers

0
votes

Solved!

The problem was the targetid property of the xf:dispatch event handler.

Instead of "error-summary", we should use "fr-error-summary-model" as targetid property value, to access to the built-in "Error Summary Component".

(inspect components.xsl, error-summary.xbl)

Sample working code:

    ...
    <xf:submission id="submit" ...
        ...
        <xf:action ev:event="xforms-submit-error">
            <!--  Listing the errors present on form -->
            <!-- 
                 1. visit-all action, which will result in marking all controls "visited", so their related error shows. 
                 2. to properly update the error summary within a submission response, we need an explicit <xf:refresh> action before dispatching....
                 3. ...fr-update, so that the UI captures all the valid/invalid  states: 
            -->
            <xf:dispatch name="fr-visit-all" targetid="fr-error-summary-model"/>
            <xf:refresh/>
            <xf:dispatch name="fr-update" targetid="fr-error-summary-model"/>
        </xf:action>
        <xf:action ev:event="xforms-submit-done">
            <xxf:script>window.parent.closeIframe();</xxf:script>
        </xf:action>
    </xf:submission>
    ...
    </xf:model>
</xh:head>
<xh:body>
    <fr:view>
    ...
    <xf:trigger id="submit-control" bind="submit-bind">
        <xf:label ref="$form-resources/submit/label" />
        <xf:send ev:event="DOMActivate" submission="submit" />
    </xf:trigger>
    ...