Changing Field to Required After Pressing Submit

Community Beginner ,
Sep 27, 2018

Copy link to clipboard

Copied

I have the following code on my Submit button set for Mouse Down.

Not sure where this code is messing up.  I am trying to have the submit button check that all required fields are filled out and if they are to make 2 specific fields required.

var emptyFields = 0;


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


  var f = this.getField(this.getNthFieldName(i));


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

   if((f.type == "text" && f.value == "") || (f.type == "checkbox" && f.value == "Off")){

  emptyFields++

  }

  }

} if (emptyFields = 0){

  this.getField("Executive or Director Signature").required = true;

  this.getField("Executive or Director Name").required = true;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

86

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Changing Field to Required After Pressing Submit

Community Beginner ,
Sep 27, 2018

Copy link to clipboard

Copied

I have the following code on my Submit button set for Mouse Down.

Not sure where this code is messing up.  I am trying to have the submit button check that all required fields are filled out and if they are to make 2 specific fields required.

var emptyFields = 0;


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


  var f = this.getField(this.getNthFieldName(i));


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

   if((f.type == "text" && f.value == "") || (f.type == "checkbox" && f.value == "Off")){

  emptyFields++

  }

  }

} if (emptyFields = 0){

  this.getField("Executive or Director Signature").required = true;

  this.getField("Executive or Director Name").required = true;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

87

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 27, 2018 0
Most Valuable Participant ,
Sep 27, 2018

Copy link to clipboard

Copied

Before getting into the issues in your code, the logic behind it doesn't make sense.

Why set the fields as required after the submit button is clicked? The entire point of this property is to validate it before submitting the form, not afterwards...

Technically, your issue is this line:

if (emptyFields = 0) {

It should be:

if (emptyFields == 0) {

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 27, 2018 0
Community Beginner ,
Sep 27, 2018

Copy link to clipboard

Copied

Thanks for catching that.  I would have looked at it for hours.

Two people are signing the form.  The first person needs to be able to submit the form to the second person.  I want the second person's signature line to be required after the first person presses submit.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 27, 2018 0
Most Valuable Participant ,
Sep 27, 2018

Copy link to clipboard

Copied

Yes, I actually thought it might be something like that... In that case, it does make sense, of course.

I would also change this line:

if((f.type == "text" && f.value == "") || (f.type == "checkbox" && f.value == "Off")){

To:

if(f.valueAsString==f.defaultValue){

It will help you cover all field types, not just text fields and check-boxes.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 27, 2018 1
Community Beginner ,
Sep 27, 2018

Copy link to clipboard

Copied

Thanks for that.

I will change that code as well.

Now I'm encountering a different issue.

If I set it for Mouse Down it will turn the fields required and block the person from submitting.

If I set it for Mouse Up or On Blur it does not turn them required.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 27, 2018 1
try67 LATEST
Most Valuable Participant ,
Sep 27, 2018

Copy link to clipboard

Copied

You should use MouseUp, but you should also add the Submit command to the script, as you can't cancel the submit command if it's not done using the script.


Add this to the end of your code:

else this.mailDoc({cTo: "target@server.com"});

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 27, 2018 1