Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Temporarily Disabling Validation

Avatar

Former Community Member
Hi,



I have a form which requires validation prior to it's final submission (fields must be populated, etc).



However, in order to pre-populate some of these fields, we also need to be able to submit the form to an external CRM to retrieve the FDF data for the form to be incorporated.



When doing this, the form is validated, and since there is no data yet, the submission fails and pre-population fails.



Is there any way to temporarily disable the validation of the form for the pre-population-submission, and then turn it back on following that?



The property xfa.host.validationsEnabled seems like a good candidate, but setting it to false doesn't seem to have any impact.



Cheers,

Martin
6 Replies

Avatar

Former Community Member
You're on the right path with xfa.host.validationsEnabled. With this property, you can enable/disable validation
scripts but you can't make required fields become optional.



I believe you have two choices:







  1. Make all your required fields optional, write validation scripts for them (if they all run the same validation, consider placing the validation script in a Script Object -- you can insert one on a subform by right-clicking on the subform in the Hierarchy palette and selecting
    Insert Script Object) and use the xfa.host.validationsEnabled property to temporarily disable the validation scripts on the "pre-population-submission". Note that you can set a Validation Script Error/Warning Message via the Object palette's Value tab.





  2. Keep your required fields as required and write script that sets all required field's
    mandatory property to "disable" during the "pre-population-submission" and sets them back to "error" afterwards.







Stefan

Adobe Systems

Avatar

Former Community Member
Thanks Stefan,



I was hoping #2 wouldn't have to be the option, but looks like I don't have much of a choice.



Cheers,

Martin

Avatar

Former Community Member
Well, just to update, I've written the functionality as described in option 2. above, but aren't having much luck.



> [SNIP]

if (node.className == "field") {

if (node.mandatory == "error") {

node.mandatory = "disabled";

xfa.host.messageBox(node.mandatory);

}

}

[/SNIP]



This shows the field as "disabled" rather than "error" as it initially is.



However, when submitting the form, I'm still presented with the validation error:



> At least one required field was empty on export. Please fill in the required fields (highlighted) before continuing.



Am I missing something obvious here when disabling the validation? I've also set xfa.host.validationEnabled to false prior to submission.

Avatar

Former Community Member
xfa.host.validationsEnabled won't affect the mandatory property of fields. It will only set whether validation scripts are executed or not.



As I described earlier, there are two ways of validating fields:







  1. Using the
    mandatory property in script or setting the Type property on the Value tab in the Object palette to
    User Entered - Recommended or
    User Entered - Required. The only way to disable this kind of validation at runtime (in Acrobat) is to use the "this.mandatory = 'disabled';" statement.





  2. Using validation scripts (scripts which evaluate to a boolean expression -- true or false) set on each field's Validate event which you can disable with the help of xfa.host.validationsEnabled. The catch, though, with script validations, is that fields with null values don't get validated (all field's with no default value are initially null when the form is first open in Acrobat).







I tried your code snippet in a little form I created and didn't find any problems. I've attached the form. In it, you'll see that there's a drop down list and a date time field which are
User Entered - Required and which get set to optional with your code snippet on the email submit button's PreSubmit event. You'll also notice that there's a text field which is
User Entered - Optional but has a validation script in its Validate event which verifies that the field's value is "1" and that validations are enabled.



When you click on the button, the drop down list and date time field become optional and you're permitted to submit the form because the text field's value is null (validation script isn't executed). If you enter anything but a single "1" in the text field and try to submit again, you won't be allowed to because of the validation script error. You can then un-comment the following line at the top of the email submit button's PreSubmit script:



//xfa.host.validationsEnabled = false;


This should let you submit the form even if the value entered into the text field is something other than "1".



If this still doesn't help, I'd be curious to know what version of Acrobat you're using.



Stefan

Adobe Systems

Avatar

Former Community Member
Thanks Stefan,



I've tried your script and yes, it works as expected. I've also put my version of the functionality into your script and included the pre-population component and it falls over.



I can't upload the form to the forum, but you can see my version at http://www.classpath.com.au/pdf/TempDisableValidations.pdf?fdfUrl=www.classpath.com.au/pdf/data.xml. The FDF data for the form is also at the location in the URL.



If you have any ideas on what I'm missing, it'd be appreciated.



Martin

Avatar

Former Community Member
Thanks for providing me with that sample of your code. I can see what's happening but I don't know for sure why those fields you're making optional are remaining mandatory. It could be a timing issue (i.e. Acrobat's Object Model hasn't been updated with the mandatory to optional changes by the time you attempt to submit the form).



I can think of two possible solutions:








  1. [Easiest of the two solutions] Since mandatory fields are flagged when they're null (when you haven't entered anything into them, which is the case on the Form:Ready event where you're executing the code which pre-submits the form to get the FDF data) and the problem you're getting is that Acrobat won't let you submit the form because it thinks some fields are mandatory, I would make all the fields optional and use Validation scripts like the one on the TextField. This way, you'll be able to pre-submit the form because all field values will be null initially and validations don't fail on null values because they aren't executed. This, however, will be a problem when the user submits the form via email because the email submit button will work even if one of the field's value is null (but now you want to make sure it's filled-in). To solve this problem, you would need to place a fake email submit button on the form (which is just a regular button), hide the real email submit button and put some validation code in its Click event. This validation code would verify that all fields contain valid data and aren't null. If this fails, you can show an error message and stop there. If all field values are acceptable, then you would execute the hidden email submit button's Click event in order to cause the form to be submitted via email:
    EmailSubmitButton1.execEvent("click");





  2. [My least-favored solution] You could try setting all fields to optional in the Form:Ready event and move your code to pre-submit and get the FDF data into an
    invisible (not hidden or else Acrobat won't let you modify its properties at runtime) text field's Validate event. The Validate event on the invisible text field would have some guards to prevent it from executing every time a field's value changes on the form. When setting fields as optional, this would cue the execution of form validations (validation scripts on Validate events) and, if certain guards are properly set, would let your pre-submit code run. It's very complicated and difficult to explain but here's a thread to which I posted a similar solution (with a sample file) which uses this approach to import XML data into a form and display a summarized output in a table:
    Grouping and Summation. See post #5 in that thread.







Let me know if you have any questions.



Stefan

Adobe Systems