13 Replies Latest reply on Nov 16, 2009 1:59 PM by noosemonsewicz

    setFocus Action

    noosemonsewicz

      I am working on an adobe form and am trying to grab the length of a textfield and then I have an if statement that will evaluate the field and if the field's length is more than the number I specify then a setfocus command should fire to the next field...

       

      var field = this.getField("desc1");
      
      if(event.field.length > 4) {
          this.getField("desc2").setFocus();
      }
      

       

      Is this possible? Cause as of right now all you can do is put an onfocus command on a textfield and I need this to act more like an onclick so it constantly reads the field

        • 1. Re: setFocus Action
          gkaiseril MVP & Adobe Community Professional

          Have you set the limit for the number of charaters for the field?

           

          Autotab

          • 2. Re: setFocus Action
            noosemonsewicz Level 1

            yes. i have it set to 25

            • 3. Re: setFocus Action
              noosemonsewicz Level 1

              can you give me an example of how to use the autoTab function? I added it to my Document Level JS... but I have NO idea how to utilize it lol

              • 4. Re: setFocus Action
                try67 MVP & Adobe Community Professional

                You're not using the event object correctly. There's no such thing as "event.field". You can either use the event object to access the field in question, OR a varibale using getField(), not both.

                Also, a field doesn't have a length property. For that you need to look at the field's value, or valueAsString.

                • 5. Re: setFocus Action
                  noosemonsewicz Level 1

                  hmmm... alright... I am used to the Web side of JS and not used to the API set to Adobe... I just (today as a matter of fact) found out that Adobe has a JS functionality for their Forms... can you give me an example?

                  • 6. Re: setFocus Action
                    try67 MVP & Adobe Community Professional

                    If you want to get the length of the value of "desc1", you can do it like

                    this:

                     

                    this.getField("desc1").value.length

                    • 7. Re: setFocus Action
                      noosemonsewicz Level 1

                      awesome! ok so I did an alert to get that to work to make sure and it did (thank you so much) but now how do I create an autoTab functionality so that after a certain amount of entered characters the next field will be tabbed to?

                      • 8. Re: setFocus Action
                        try67 MVP & Adobe Community Professional

                        Set a maximum length and enter this as a custom keystroke script:

                        if ( event.fieldFull || event.willCommit )

                        this.getField("desc2").setFocus();

                         

                        This code is taken from the reference file. You should really use it if you

                        want to learn how to use JS in Acrobat.

                        • 9. Re: setFocus Action
                          noosemonsewicz Level 1

                          hmm I saw this and didn't know how to implement it cause the only triggers you have are on mouse events, focus, and blur, but how do you add a custom trigger in?

                          • 10. Re: setFocus Action
                            try67 MVP & Adobe Community Professional

                            Format tab, Custom, Custom Keystroke script

                            • 11. Re: setFocus Action
                              noosemonsewicz Level 1

                              YOU FREAKIN ROCK!!!!!!!!

                              • 12. Re: setFocus Action
                                gkaiseril MVP & Adobe Community Professional

                                There is an attached sample you can download. If you want it to trigger at 4 the field length should be 4.

                                 

                                The document level script;

                                 

                                function goNextAlpha(oItem, oEvent, cName, bAlpha) {
                                /* Tab to next field when field character limit is reached.
                                   Includes alpha fields and case change.
                                   Includes error trapping and displays on JavaScript console
                                   the error, field where error occurred and next field name.

                                   parameters:
                                   oItem  - required - item where fields  to process reside
                                   oEvent - required - field being processed
                                   cName  - required - next field's name
                                   bAlpha - optional - identifies an alpha field

                                   Place call to this function in the fields custom format.
                                   The user responsible for checking format of field.
                                   Default number check is for the standard numeric values.
                                   "0-9" for single character fields and includes sign values for multi character fields.

                                   Call for number field:
                                   goNextAlpha(this, event,"NextField");

                                   Call for alpha with forced upper case:
                                   goNextAlpha(this, event "AlphaNextField", true);

                                */
                                try{ // error catcher
                                  if (bAlpha) {
                                     if (AFMergeChange(oEvent).length == oEvent.target.charLimit) oItem.getField(cName).setFocus();
                                     }
                                  else {
                                  AFNumber_Keystroke(0, 0, 0, 0, "",true);
                                  }
                                if (oEvent.rc && AFMergeChange(oEvent).length == oEvent.target.charLimit) oItem.getField(cName).setFocus();
                                } catch(eMsg) { // trap error display error message, field in and next field
                                app.beep(3); // beep
                                } finally {  // always run
                                return; }

                                } //end // goNext

                                The custom keystroke script for a field, ssn9.0:

                                 

                                goNextAlpha(this, event, "ssn9.1");

                                 

                                Since the required input is 1 number, the maximum field size is set to 1.

                                 

                                The test statement for the 'if' test is:

                                oEvent.rc && AFMergeChange(oEvent).length == oEvent.target.charLimit

                                 

                                So the length of the inputed data and the 'charLimit'  property trigger the 'setFocus()' method.

                                • 13. Re: setFocus Action
                                  noosemonsewicz Level 1

                                  Thanks for everyones help! It is true about learning something new every day