Skip to main content
stefaniag52382534
Participant
Feb 12, 2019 3:37 PM UTC
Answered

How to put multiple text fields into an array list?

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

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Feb 12, 2019 3:40 PM UTC

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.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Feb 12, 2019 3:40 PM UTC

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