Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

validate required fields using print form button

Avatar

Former Community Member
I have a form that user can fill out online and then print. I have fields set as required. How can I add a pre-print function to check for blank fields before allowing the print function?



I know that a submit button creates the correct action so how can that function be added to the print button where it only allows the print to work if the required fields are filled in.
7 Replies

Avatar

Former Community Member
If you set the fields as required, then when the user hits the print button you could run this script:



var txt = form1.execValidate();

if (txt == true){

print command

}



This code assumes that the root node of your form is form1. Also ensure you put a message into the Empty Message parameter for each field that you want to mark s required.

Avatar

Former Community Member
The current code for the print button is:



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



This is javascript mode run at client.



I tried replacing that code with yours, adding it before and after the above string...nothing seems to work.

or do I add it as a validate? Very confused.



Thanks

Avatar

Former Community Member
So set up your mandatory fields like you normally would. Make sure that you have a nessage displayed (as I mentioned above) and then add this code to the print button click event.



var txt = form1.execValidate();

if (txt == true){

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

}

Avatar

Former Community Member
I added that code exactly as shown and now the print button does nothing. If I remove everything but the xfa.host.print........ it works like normal.



I just wonder if the form1 name is wrong and my form is something different.



where can I find the form name in the xml code?

Avatar

Former Community Member
YEH! I figured it out. It was the form name.



The code had to be;



var txt = topmostSubform.execValidate();

if (txt == true){

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

}



Now that I know what to look for in the XML I can do this again.



Thanks, ME!

Avatar

Former Community Member
New question: Does anyone know how to remove or change the red border that shows up when you make a field required?