Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to put multiple text fields into an array list?

New Here ,
Feb 12, 2019 Feb 12, 2019

Hi guys before continuing i must say that I'm very new to Adobe javascript and his community,this is my first question.

I am making a form with acrobat pdf at the last part of the module I put a "save" button linked with an action when pressed the mouse,before doing its task, It's check also if all fields are full or not.

There are some specific text fields that are not required..

So my question is How can i put them into an array list and then delete them?  for example with splice(); method?  

var emptyFields = []; 

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

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

     if(f.type=="text" && f.value=="") {   emptyFields.push(f.name);  

     }

}    

if (emptyFields.length>0) {  app.alert("Errore! è necessario compilare i seguenti campi obbligatori:\n" + emptyFields.join("\n"),0);

      }

else{  app.alert("Tutti i campi sono stati compilati con successo!",3);

//here then I can save the document form     

}   

This is the first part of the code

TOPICS
PDF forms
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Feb 12, 2019 Feb 12, 2019
LATEST

If you marked the fields as required then change this part of the code (which I believe I wrote, by the way):

if (f.type=="text" && f.value=="")

To:

if (f.required && f.valueAsString==f.defaultValue)

That will also cause it to work with other field types, not just text fields.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2019 Feb 12, 2019
LATEST

If you marked the fields as required then change this part of the code (which I believe I wrote, by the way):

if (f.type=="text" && f.value=="")

To:

if (f.required && f.valueAsString==f.defaultValue)

That will also cause it to work with other field types, not just text fields.

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