Expand my Community achievements bar.

Found easy way to trigger full form validation with one line of code (work 4 validate b4 printing)

Avatar

Former Community Member
i found a super cool secret code to validate the whole form in one line of code!



F.execValidate();



so to validate before printing, my print button is a normal button (not a print button)with this code for onclick:



if(F.execValidate())

{

xfa.host.print(1, "0", (xfa.host.numPages - 1).toString(), 0, 1, 0, 0, 0);

}



my "validate data" button just has:



if(F.execValidate())

{

xfa.host.messageBox("Data is valid!");

}



- no need to put an error in the else since if it finds errors in any fields, it pops up thoes error messages.



easy as that!



IMPORTANT!:

- unfortunatly it does not check if required fields are empty

- it only checks the "validation pattern" under Object > Value

- the "Error" box beside "validation pattern message" MUST be checked (if it is not checked, your validation errors will still popup, but the function will return true when it should be false - and therefore the print box will popup)

- the adobe designer reference manual says that execValidate() returns "empty" so putting the function in an if statement may not always return true or false....it is working for me, but if the documentation doesnt match, it could possibly change at any time...



if someone finds a way to trigger checking for empty required fields, please let me know. I tried:



F.execEvent("preSubmit");



which i hoped would call all the stuff submitting does before its submitted, but it doesnt - of course



hope this helps!
0 Replies