Skip to main content
Participant
December 31, 2020
Answered

Submit Button Highlights Filled In Required Fields

  • December 31, 2020
  • 4 replies
  • 12174 views

I have a form with several required fields. When the submit button is clicked and ONE of the required fields is blank an error message is displayed "At least one required field was empty. Please fill in the required fields (highlighted) before continuing". The issue is that ALL of the required fields are highlighted even if they are not blank. Is there a way to highlight just the field(s) that are blank? 

Correct answer ls_rbls

You can try with a mouse-up event action script like :

 

// loop through all fields in the document

for ( var i=0; i < this.numFields; i++) {

//get the field names and declare variables
var fname = this.getNthFieldName(i);
var f = this.getField(fname);


/*establish a condition, if the field is not a button type object, and fields are marked as required but the value is empty */

if (f.type != "button" &&  f.required == true) {

if (f.value == "") {


//trigger an alert for the user to identify which fields are empty

app.alert({

cMsg: "Please complete required field(s) before submitting this form: " + f.name,

cTitle: "Required Fields Check "});

}
} 

 

This is just a very small example of this type of script. You can add more to it.

 

 

4 replies

Participant
November 3, 2023

I know I am late to the game. I have the same error message, when I run the Java script it says: SyntaxError: 1:Console:Exec undefined?

Help

ls_rbls
Community Expert
Community Expert
November 12, 2023

HI @Yvonne33372078ja52 ,

 

Would you mind sharing the script that you're using? Or better yet, a copy of your PDF (if you can).

Participant
January 8, 2021

This was effective, thanks so much.

There is still one slight issue. Error messages pop up for all blank fields, but then the default message "At least one required field was empty. Please fill in the required fields (highlighted) before continuing" also appears the last time OK is clicked. Is there script that could be added so the default message doesn't appear? I'm not really familiar with Java so I very much appreciate the help.

ls_rbls
Community Expert
Community Expert
January 8, 2021

You're welcome.

 

That seems to be a buitl-in system messaging app when the submit form action is used, and it takes precedence over any custom script JavaScript if both actions (the script or built-in submit form action) are triggered from the same button. So, it was very difficult for me to figure out  how to supress that alert via scripting.

 

What probably could work to avoid this, is to make two buttons; one button visible and one button hidden.

 

The main button (visible) could have an condition that when it runs the script that checks for the empty required fields, and if they're all filled in then second button becomes visible so that the user just clicks on it and submit.

ls_rbls
Community Expert
Community Expert
January 1, 2021

++Adding to AkanchaS guidance,

 

You can  also add a JavaScript  mouse-up event action to that button to check for the fields that are marked as required but not empty and  those that are marked as required but empty, and pop an alert message to encourage the user to complete filling in those empty required fields before the Submit action is executed.

 

That said, if you select to submit the form exported  as an FDF file.

 

Under this export option, the Submit action allows you to select an additional option to send the form with empty fields marked as required.

 

You won't get that option if you opt to send the entire dopcument exported as PDF.

 

See slide below:

 

Participant
January 2, 2021

Thank you for your response.

 

The form does not have any hidden mandatory fields. The users are using Acrobat Reader to fill in the form.

 

Would you or anyone else by chance have an example of the JavaScript  mouse-up event action script? 

Participating Frequently
February 21, 2023

I will take a look at the file.

 

Both scripts worked for me as Mouse Up action. I would like to test the scripts the way you have it  as Mouse Down and Mouse Exit.

 

I also need to see how it behaves with the web browser.


Hello ls_rbls

Just wondering if you've had an luck with the form?

Thanks

AkanchhaS8194121
Legend
January 1, 2021

Hi,

 

While creating the form, did you create there any hidden manadatory fields ? Please cross check and see if there is any hidden mandatory fields and you might have applied the same settings to all the form fields available there.

The end users who are filling the form, do they fill it within Acrobat/Reader desktop app or on web browser?

 

Thanks,

Akanchha