Skip to main content
Participating Frequently
September 27, 2018
Question

Changing Field to Required After Pressing Submit

  • September 27, 2018
  • 1 reply
  • 590 views

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;

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
September 27, 2018

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) {

rhadaviAuthor
Participating Frequently
September 27, 2018

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.

try67
Community Expert
Community Expert
September 27, 2018

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.