Skip to main content
Inspiring
May 10, 2023
Answered

Find blank field in a group of fields

  • May 10, 2023
  • 1 reply
  • 3420 views

I have a document with 10 sections. Each section has 10 fields , section 1 (jt1.01 to jt1.10), section 2 (jt2.01 to jt2.10), and so on.

Could someone please help me for adobe javascript code to find any empty field (all are text fields) in a section and alert me to fill the blank field(s) before signing the section and make all fields readonly.

 

Thanks in advance

This topic has been closed for replies.
Correct answer Joe2787079753nv

You can apply it to all (text) fields using this code:

 

for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	var f = this.getField(fname);
	if (f==null) continue;
	if (f.type=="text") f.setAction("Keystroke", "spacebar();");
}

 

Note this will overwrite any previous Keystroke actions (and also Format, in some cases) you selected, though.


Thanks try67,

WOW - I am impressed with the level of experties of the Adobe Support Community Experts and their responsiveness.

Your code worked perfectly. 

I modified your code for a selected section as an array (rather than the entire document) as Ms. Nurani advised earlier [ for( var j in f){
if (f[j]==null) continue; if (f[j].type=="text") f[j].setAction("Keystroke", "spacebar();");}].

I am really greatful for your help. 

Thanks again.

 

 

1 reply

Nesa Nurani
Community Expert
Community Expert
May 11, 2023

This will list all empty fields:

var fields = [];
for(var i=1; i<=10; i++){
var f = this.getField("jt"+i).getArray();
for( var j in f){
if(f[j].valueAsString == "")
fields.push(f[j].name);}}
if(fields.length != 0)
app.alert("Please fill in blank fields:\n"+fields.join("\n"));
Inspiring
May 11, 2023

Thanks so much for a quick response.

It worked like a charm. The only thing I had to change was change "jt" to "jt.".

I created a Button "jt-click" and placed the code in "Actions", "Mouse Up", "Run a Javascript". The fields are named jt.1 to jt.10, When "jt-click" is pushed, a list of blank fields is displayed.

What additional code I need to add to "jt-click" Button in order to make it disappear if all 10 text fields are filled.

Thanks in advance again.

Nesa Nurani
Community Expert
Community Expert
May 11, 2023

In your first post, you wrote that you had 10 sections with 10 fields in each, named jt1.01-jt1.10, jt2.01-jt2.10...etc.

Now you wrote fields are named jt.1-jt.10, does that mean you only have 10 fields?

If your fields are named as you stated in the first post, and you changed to "jt." script won't work.

 

What additional code I need to add to "jt-click" Button in order to make it disappear if all 10 text fields are filled.

If all fields are filled alert won't pop.