Expand my Community achievements bar.

Validation questions: How to turn it off, and how to check to see if a form is valid

Avatar

Former Community Member
Hi all,



I'm looking for some assistance with validation on a form / Form guide. Basically there are two things that we need to be able to do.



1) We need to be able to disable all the validation on a given form / Form Guide so that we can perform a submit operation to save all the data currently on the form.



2) We also need to be able to make the determination of whether or not a form is valid. The validity of the form would be passed with the form during the submit process.



Towards that end, I have been looking into the properties "validationsEnbled" and "disableAll". Neither one of which seem to do anything at all.



Any assistance you could provide would be greatly appreciated.



Thanks in Advance.



Steve
5 Replies

Avatar

Former Community Member
If you want to break the request down further, what we really want is the ability to insert our own code in front of the submit process.



In the past on PDF forms we have achieved this by hiding the submit button and adding a second regular button labeled "Submit". Selecting this button would allow us to execute our own code before using execEvent("click") to select our hidden submit button.



With form guides we can't use this approach. The workspace captures the submit button, and we can't insert our own code in front of it.



Any suggestions?



Regards,



Steve

Avatar

Former Community Member
In the guide properties you can set the submit to go from the PDF or the guide ...I woudl set it to go from the PDF then your normal technique can apply.

Avatar

Former Community Member
The problem is with using the Submit from PDF is that the fields on the form guide are still validated before you switch from the Form guide to the PDF.



Further investigation has revealed that once you set a field to be mandatory in a form guide, you cannot remove that setting. Seems like a definite bug to me. Have reported it to Adobe support.



In the mean time, does anyone else have any ideas? Could we for example edit the .swc and disable the validation step altogether?

Avatar

Level 6

Hi Steve,

Did you ever work this out?  I have a similar requirement, but I'm not using form guides.  I need a submit button that doesn't check the validations so that I can save the incomplete form.  I'll have a second submit button that does check the validations.  I have thought of two approaches, but I'm hoping there's a better idea:

1) In my "draft" submit button, put a script that loops through the form objects and sets the mandatory objects to non-mandatory.  I would use the technique of a normal button that runs a script and programatically clicks the real, invisible submit button.  Similarly, I would have to mandatorize all the fields again programatically using my "final" submit button.

2) Don't use mandatory fields at all.  Just do my null checking using script.  I don't like this one because I lose the nice red borders that don't print.

Thoughts?  It sure would be nice to have a submit button with an option of not checking the validations.

Jared Langdon

Avatar

Level 6

Okay here's a nice little function I wrote to turn off all the mandatory fields in your form.

function unMandatoryAll() {
    //makes all mandatory fields not mandatory anymore

    var oFormRoot = xfa.form.nodes.item(0);
    var arrMandatoryFieldNames = findMandatories(oFormRoot, new Array());

    for (var i=0; i<arrMandatoryFieldNames.length; i++) {
        var oCurrentField = xfa.resolveNode(arrMandatoryFieldNames[i]);
        oCurrentField.validate.nullTest = "disabled";
    }   
}

function findMandatories(oFormNode, arrMandatoryFieldNames) {
    //loops recursively through all fields in the given oFormNode and builds up a list of field names (actually SOM expressions)
    var oChildNodes = oFormNode.nodes;
    var nNumberOfChildNodes = oChildNodes.length;
    for (var i=0; i<nNumberOfChildNodes; i++) {
        var oCurrentNode = oChildNodes.item(i);
        var strNodeType = oCurrentNode.className;
        if (strNodeType == "subform")
            arrMandatoryFieldNames = findMandatories(oCurrentNode, arrMandatoryFieldNames);
        if ((strNodeType == "field") || (strNodeType == "exclGroup")) {
            if (oCurrentNode.validate.nullTest == "error")
                arrMandatoryFieldNames.push(oCurrentNode.somExpression);
        }
    }
    return arrMandatoryFieldNames;
}

Jared Langdon

http://www.jlangdon.ca