Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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"));
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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"));
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You are correct. I just changed field names to simplify the testing process. All is working now. Thanks again for your expert advice and input.
Copy link to clipboard
Copied
Ms. Nurani,
Thanks for solving my first problem regarding blank fields.
How could I modify the above codes not to allow space bar as first character for the blank fields. I do not want to use custom Keystroke for each field.
var v= AFMergeChange (event);
if (/^\s/.test(v)) event.rc=false;
Thanks in advance again.
Copy link to clipboard
Copied
Put the code in a doc-level function and then call it from each field.
Copy link to clipboard
Copied
Thanks TRY67,
I am a good chemist but a novice Adobe JavaScript programmer. I create interactive forms using Adobe Acrobat 10 Pro for some of the work I do.
How do I put the code in a doc level in Acrobat 10 Pro and how do I call it from each field?
Thanks in advance.
Copy link to clipboard
Copied
Hi try67,
I found one of your posts about doc-level scripts.
1- Created a function called "spacebar" at doc-level
function spacebar()
{var v = AFMergeChange(event);
if (/^\s/.test(v)) event.rc = false;
}
2- Then tried to get the "spacebar ();" funtion at the field level by entering,
spacebar ();
in the test field properties "Calculate" - Custom calculation script.
Still I can enter space bar in the field. How do I call the "spacebar ();" function in the field?
Thanks
Copy link to clipboard
Copied
Not in calculation, go to 'Format' tab and select 'Custom' and put spacebar(); in 'Custom keystroke script'.
Copy link to clipboard
Copied
Thanks Ms. Nuurani,
That worked perfect.
However, I was hoping to have the codes in a separate field that when it checks for empty fields in a section also dis-allow spacebar entry as first character for all fields in that section. Right now, I need to go to each individual Text Field Properties,, select Format, Custom, Custom Keystroke Script - and enter the "spacebar ();". It is time consuming to do this for about 100 fields and also adds to the size of the file. I was hoping for a simpler way.
Thanks again in advance
Copy link to clipboard
Copied
What is the naming of the fields?
You can use loop and setAction() to put script in all fields at once.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now