Skip to main content
Participant
January 17, 2026
Answered

Submit button check if all the required fields are filled in and lock them

  • January 17, 2026
  • 1 reply
  • 131 views

Good evening,

 

I'm trying to program a Submit button, in one click it should check that the required fields are filled in (Except for some of them) and lock them once it's correct.

 

I'm posting my code, not sure what I'm doing wrong. Probably everything.

 

 

var nButton = app.alert ("Are you sure you want to submit the Staging Pre-Configuration Request? After submission the form won't be editable.",1,2);

if (nButton == 4){


var aExcept = [ "Stag_Comm", "Ret_Date_af_date", "Sta_Name", "Sta_Sign", "Sta_submit", "Remove Page", "Add Page", "Pic_1_af_image", "Pic_2_af_image", "Remove Page Template", "Add Page Template", "Pic_1 Template_af_image", "Pic_2 Template_af_image" ];

 


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

{var name = this.getNthFieldName(i);

{if (aExcept.indexOf(name) == -1)

{var f = this.getField(name);

var emptyFields = [];

if (f.type!="button" && f.required && f.value == f.defaultValue) {emptyFields.push(f.name);}


if (emptyFields.length>0)
{app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));}

else

{if (f != null)
{f.readonly = true;
}

}
}

 

for(var i = this.numFields - 1; i > -1; i--)
{

 


this.getField("Req_submit").display=display.hidden;

}
}
}
}
else
{app.execMenuItem("Save")}

Correct answer try67

Use this code, and remove any other command you have under that button:

 

var nButton = app.alert("Are you sure you want to submit the Staging Pre-Configuration Request? After submission the form won't be editable.", 1, 2);
var emptyFields = [];
if (nButton == 4) {

    var aExcept = ["Stag_Comm", "Ret_Date_af_date", "Sta_Name", "Sta_Sign", "Sta_submit", "Remove Page", "Add Page", "Pic_1_af_image", "Pic_2_af_image", "Remove Page Template", "Add Page Template", "Pic_1 Template_af_image", "Pic_2 Template_af_image"];

    for (var i = 0; i < this.numFields; i++) {
        var name = this.getNthFieldName(i);{
            if (aExcept.indexOf(name) == -1) {
                var f = this.getField(name);
                if (f.type != "button" && f.required && f.value == f.defaultValue) {
                    emptyFields.push(f.name);
                }
            }
        }
    }
   
   if (emptyFields.length > 0) {
        app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
    } else {
		for (var i = 0; i < this.numFields; i++) {
			var name = this.getNthFieldName(i);
			var f = this.getField(name);
			if (f != null) f.readonly = true;
		}
		this.getField("Req_submit").display = display.hidden;
		this.mailDoc({cTo: "me@email.com"});
	}
}

1 reply

try67
Community Expert
Community Expert
January 18, 2026

Move this line to be the first one of the code:

var emptyFields = [];

Be aware that the Save command is not going to work, though. This command requires a special context to run from.

Participant
January 18, 2026

I did and the doesn't do anything.

I would like to check first that all the required fields except for a few ones filled in and then lock them.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 18, 2026

Use this code, and remove any other command you have under that button:

 

var nButton = app.alert("Are you sure you want to submit the Staging Pre-Configuration Request? After submission the form won't be editable.", 1, 2);
var emptyFields = [];
if (nButton == 4) {

    var aExcept = ["Stag_Comm", "Ret_Date_af_date", "Sta_Name", "Sta_Sign", "Sta_submit", "Remove Page", "Add Page", "Pic_1_af_image", "Pic_2_af_image", "Remove Page Template", "Add Page Template", "Pic_1 Template_af_image", "Pic_2 Template_af_image"];

    for (var i = 0; i < this.numFields; i++) {
        var name = this.getNthFieldName(i);{
            if (aExcept.indexOf(name) == -1) {
                var f = this.getField(name);
                if (f.type != "button" && f.required && f.value == f.defaultValue) {
                    emptyFields.push(f.name);
                }
            }
        }
    }
   
   if (emptyFields.length > 0) {
        app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
    } else {
		for (var i = 0; i < this.numFields; i++) {
			var name = this.getNthFieldName(i);
			var f = this.getField(name);
			if (f != null) f.readonly = true;
		}
		this.getField("Req_submit").display = display.hidden;
		this.mailDoc({cTo: "me@email.com"});
	}
}