Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Empty field Validation before Print, What's Wrong with THIS code??


Level 2

I have been trying unsuccessfully to get this code to work.. I am stumped!  I created a print button.  Then added this script under "Form Calc" in the Click event of the button.  But when clicked nothing happens.  I have a radio button group that has different options but I only want to make the field NameofReferralSource required if the user checks Broker.  The print button is on page 1.  The field and radio button group are on page 7.  I just can't figure out how to get this to work.  I don't necessarily need to make the fields required since then I would have to add script remove the red border and add a message telling user where the field is otherwise they will have to search through 6 pages to find it. (maybe a better solution?)  I just want a simple code that fires when the user hits the Print, Save, or Submit button to check if Broker name is empty and if it is, prompt them to fill in.  Help!

if ((topmostSubform.Page7.NameofReferralSource.rawValue == null)  & (topmostSubform.Page7.Howdidyouhear.0.rawValue == "Broker")) then

xfa.host.messageBox("You must enter the the Name of the Broker under Referral Name on Page 7 to be able to print this form")





3 Replies


Level 2

Ok, well my reference to the fields were incorrect.  Here is the new code:

if (Page7.NameofReferralSource.rawValue == null){

xfa.host.messageBox("You must enter the the Name of your Referral on the bottom of Page 7 to be able to print this form");



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

The first part that checks for an empty field and displays a message works however the print dialog still pops up after the user clicks ok to the error message.  Any ideas?


Level 2

OKKKK, answered my own question.  I created a hidden button and added the print command to the click event and removed the print command from

the dummy print button.  Everything works great!


Former Community Member

What do you mean you created a hidden button?  Also were u able to do this to more than one field?