How can I create my own validation rule in orbeon xforms?
Here is the problem, I need to validate the form before submitting as follows, before the user can submit anything he has to click on the "Save" button, if he tries to click on "Submit", then he will get a "Save Forms Before Submit" message.
At first I thought I could add a system field to the form like save-indicator, add a constraint like
<xforms:bind id="isSaved-bind" nodeset="isSaved" name="isSaved" type="xforms:string" constraint="number(.)=1" required="true()"/>
to actions when clicking the "Save" button.
But the problem is that I have to rewrite all existing forms to insert new code there.
Is it possible to make a global variable like "isSaved" and check it for each form before submitting and show an error message if the user hasn't saved the form?
Or maybe there is another way that I can't see?
Any answers will be appreciated.
source to share
The Form Runner keeps track of whether the form is clean or dirty and you can access this information in
. The code that handles the submission is in
. There you can change the listener for
<xforms:action ev:event="DOMActivate" ev:observer="fr-submit-button"> <xforms:action if="instance('fr-persistence-instance')/data-status = 'clean'"> <xforms:setvalue ref="instance('fr-persistence-instance')/submit-or-save-or-send">submit</xforms:setvalue> <xforms:dispatch name="fr-save-action" target="fr-persistence-model"> <xxforms:context name="fr:check-data-valid" select="true()"/> </xforms:dispatch> </xforms:action> <xforms:action if="instance('fr-persistence-instance')/data-status = 'dirty'"> <xforms:message>You must save form before submitting it.</xforms:message> </xforms:action> </xforms:action>
Please note what
. To modify this file, extract it from there and place it in
. This version
will not take precedence over the file in the jar file. Also note that these types of changes, which depend on the internal components of the Form Runner or Form Builder, have a chance of breaking when upgrading to a newer version of Orbeon Forms. This way you can track them closely so that you can more easily reapply the changes when you upgrade.
source to share