The Error Summary component is a reusable component listing the errors present on your form (or a sub-form):
attribute points to a control to observe. That control and all the descendants of that control are surveyed for changes in validity:
The title can be dynamic, e.g. for localization purposes:
If specified, the following attributes point to nodes into which the error summary makes useful information available to you:
event to the error summary. This:
- makes the summary consider all controls under the configured observer(s) as visited
- marks all controls under the configured observer(s) as visited by adding the
xforms-visited and xforms-alert-active-visited classes
This is useful when the user, for example, presses a "Save" button: in that case, you might want to show all the errors on the form right away:
<xforms:trigger>
<xforms:label>Save</xforms:label>
<xforms:dispatch ev:event="DOMActivate" name="fr-visit-all" targetid="my-error-summary"/>
</xforms:trigger>
When you do this, make sure that
<fr:error-summary> has an id:
<fr:error-summary observer="my-group" id="my-error-summary">
...
</fr:error-summary>
Then, to disable the alert icon on invalid controls, until either users went through the control, or users did an action (such as "Save") that dispatched an fr-visit-all, add the following CSS. The first rule disables the background image and the second one enables it, overriding the first rule in cases where the alert is both active and the control is visited. Most likely, you will need to modify the relative path in the second rule, depending on the location of your CSS file. The path should resolve to
/your-all/ops/images/xforms/exclamation.png if you are not in separate deployment, and
/your-app/orbeon/ops/images/xforms/exclamation.png if you use separate deployment. Note that it is better here to have a relative URL (adjusting the number of
.. in the path) rather than an absolute URL (starting with
/your-app), as a relative URL allows you to change the context of your application without having to change the CSS.
.xforms-alert-active { background-image: none }
.xforms-alert-active-visited { background-image: url(../../../ops/images/xforms/exclamation.png) }
Marking all controls as not visited
You can dispatch the
fr-unvisit-all event to the error summary. This:
- makes the summary consider all controls under the configured observer(s) as not visited
- marks all controls under the configured observer(s) as not visited by removing the
xforms-visited and xforms-alert-active-visited classes
Adding a header and a footer
When there are no visible errors, the entire body of the error summary is hidden. You can had your own header and footer content within that body so it hides and shows depending on whether there are errors or not. Just add the
<fr:header> and
<fr:footer> elements:
<fr:error-summary observer="my-group">
<fr:label>Your Form Contains the Following Errors</fr:label>
<fr:header><xhtml:div class="fr-separator"> </xhtml:div></fr:header>
</fr:error-summary>
Global errors
In addition to errors related to controls, the error summary can handle global errors:
<fr:error-summary observer="my-group">
<fr:errors nodeset="instance('errors')/error">
<fr:label ref="label"/>
<fr:alert ref="alert"/>
</fr:errors>
</fr:error-summary>
The
fr:errors element takes a
nodeset attribute and iterates on a list of nodes containing information about global errors. If the node-set returned is empty, no global error is displayed.
The nested
fr:label (optional) and
fr:alert elements are evaluated relative to each node in the node-set. They return respectively:
- A label text displayed to the left
- An alert text displayed to the right
Non-incremental mode
By default the error summary updates the list of error as they occur on the form.
By specifying the
incremental="false" attribute, errors only show on demand with the
fr-update and
fr-clear events.
<fr:error-summary observer="my-group" id="my-error-summary" incremental="false">
...
</fr:error-summary>
To update the visible list of errors with the actual errors in the form, dispatch the
fr-update event:
<xforms:dispatch name="fr-update" targetid="my-error-summary"/>
To clear the visible list of errors, dispatch the
fr-clear event:
<xforms:dispatch name="fr-clear" targetid="my-error-summary"/>
To properly update the error summary within a submission response, you might need an explicit
<xforms:refresh> action before dispatching
fr-update, so that the UI captures all the valid/invalid states:
<xforms:action ev:event="xforms-submit-done">
<xforms:dispatch name="fr-visit-all" targetid="error-summary"/>
<xforms:refresh/>
<xforms:dispatch name="fr-update" targetid="error-summary"/>
</xforms:action>