9 Replies Latest reply on Nov 27, 2017 12:06 PM by Fango24

    How to fill out empty fields automatically?

    Fango24

      Hi all,

       

      I'm creating a pdf right now which has to be filled out by our customers.

      Due to Audit restrictions every field has to contain a valid value. - if nothing is entered the field should display "n.a.".

       

      My code right now:

      event.rc = true;

      if (event.value==""|| event.value ==""||event.value==0)

      {

          event.value="n.a."

      }

       

      Problem is: It's valid only for one field and triggered by selecting the cell. - I'm searching for something like a Loop which checks all empty cells after finishing the editing.. (at saving, or signing digitally)

       

      Many thanks in advance, I appreciate it

       

      kindly regards Fango

        • 1. Re: How to fill out empty fields automatically?
          JR_Boulay Adobe Community Professional

          Can't you place the "n.a" as the default value?

          And then use a script to automatically delete the default text when the field get the focus?

           

          It would be easier.

          • 2. Re: How to fill out empty fields automatically?
            Fango24 Level 1

            Hi JR_Boulay,

             

            I have already thought of that, but it would be much better-looking/ more professional the other way around.

            Setting the default value to "n.a." is my stopgap

             

            Thank you & regards

            • 3. Re: How to fill out empty fields automatically?
              JR_Boulay Adobe Community Professional

              You can try this script (not tested):

               

              for (var i=0; i<this.numFields; i++) {
                  var f = this.getField(this.getNthFieldName(i));
                  if (f != null) {
                      if (f.type == "text") {
                          if ((f.value == "") || (f.value == " ") || (f.value == 0) || (f.value == null)) {
                              event.value = "n.a.";
                          }
                      }
                  }
              }
              
              • 4. Re: How to fill out empty fields automatically?
                Fango24 Level 1

                if ((f.value == "") || (f.value == " ") || (f.value == 0) || (f.value == null))*) - had to add this bracket, but unfortunatly it only fills the selected cell. - is there something like a global console for the whole pdf?  

                • 5. Re: How to fill out empty fields automatically?
                  Fango24 Level 1

                  "Can't you place the "n.a" as the default value?

                  And then use a script to automatically delete the default text when the field get the focus?"

                   

                  Unless somebody has another solution, i think i will go with this way. - May I ask you to Show me the code?

                   

                  Many thanks in advance

                  • 6. Re: How to fill out empty fields automatically?
                    JR_Boulay Adobe Community Professional

                    Oops!

                    But as I wrote: not tested…

                     

                    This one was tested:

                     

                    for (var i=0; i<this.numFields; i++) { 
                        var f = this.getField(this.getNthFieldName(i)); 
                        if (f != null) { 
                            if (f.type == "text") { 
                                if ((f.value == "") || (f.value == " ") || (f.value == 0) || (f.value == null)) { 
                                    f.value = "n.a."; 
                                } 
                            } 
                        }
                    }
                    

                     

                    1 person found this helpful
                    • 7. Re: How to fill out empty fields automatically?
                      Fango24 Level 1

                      That's exactly what i needed THANK you!

                       

                      One small Problem still occurs:

                      If i enter a value within the "triggercell" i get a note, that the Format of the date is wrong (another cell within the doc), which is correct due to the fact, that i didn't insert one. - After that approx. the half of the boxes are filled with [n.a.] - If i now change the value of the triggerbox again, the error occurs another time, but now the rest gets filled out..

                       

                      Do you have an idea why?

                       

                      Thank you very much for your help so far ..

                      • 8. Re: How to fill out empty fields automatically?
                        Thom Parker Adobe Community Professional

                        When formatting is selected for a text field, Acrobat inserts JavaScript into the validate, format, and keystroke event scripts. It is this code that is causing the problem. Either Remove the formatting altogether, or remove the validation scripts from the date fields with this code

                         

                        this.getField("DateField").setAction("Validate","");

                         

                        This retains the date formatting, but removes validation.

                         

                        Another option is to replace the Format Event scripts in all text fields with code to display n.a..  Then you don't need to test all the fields after  the form is filled. All fields correctly display a value all the time.

                        Use the same loop JR presented above to run this code

                         

                        f.setAction("Format","if(/^\s*$/.test(event.value)) event.value = 'n.a.'; ");

                         

                        Values set in the Format event do change the true value of the field, they only modify what is displayed in the field. So this is a great place to set the "n.a." display

                        2 people found this helpful
                        • 9. Re: How to fill out empty fields automatically?
                          Fango24 Level 1

                          Alright, thank you. I‘ll try it tomorrow