4 Replies Latest reply on Feb 14, 2010 1:18 PM by Angetes

    moving to the next field

    Angetes

      Hi

       

      I want to create a script where I can type in 2 upper case letters they are validated to ensure that they are indeed two letters and if so automatically move to the next field. If not the cursor returns to the text1 filed to be amended.

       

      I created a text field which has a comb of 2 characters. Then I created another text field for the cursor to move to.

       

      I then placed this code into custom keystroke script of  the first text field.

       

      var checkit = /^[A-Z]{2}$/;
      event.change = event.change.toUpperCase();
      if (event.value != "")
      {

      if (checkit.test(event.value) == false)
           {
              app.alert("Invalid entry");
              this.getField("text1").setFocus()
              event.rc = false
           }

           else

           {
              this.getField("text2").setFocus()
           }


      }

      However it doesn't want to work.

       

      Can anyone please point me in the right direction?

       

      TIA

        • 1. Re: moving to the next field
          Appligent Level 1

          If you keep only the following line in the Custom Keystroke Script:

           

          event.change = event.change.toUpperCase();

           

          Then move the rest of your script (removing the Upper Case line) into either a custom format script or an On Blur action then this works great.

          1 person found this helpful
          • 2. Re: moving to the next field
            MarkWalsh Level 4

            That's because the keystroke event will only be the current key entered, not all of the characters that have been entered. Try something like this:

             

             

             

            var re = /[A-Z]/

             

            if (event.change.length >0) {

            if (event.willCommit == false) {

                if (!re.test(event.change)) {

                    event.rc = false

                }

            }

            }

            or alternatively, use this to convert to upper case:
            var re = /[A-Za-z]/
            if (event.change.length >0) {
            if (event.willCommit == false) {
                if (re.test(event.change)) {
            event.change = util.printx(">AA", event.change);
                } else {
                    event.rc = false
                }
            }
            }
            1 person found this helpful
            • 3. Re: moving to the next field
              gkaiseril MVP & Adobe Community Professional

              You have to compare the 'AFMergeChange(event).length' and 'event.target.charLimit' and when equal you will need to 'setFocus' to the next field.

              • 4. Re: moving to the next field
                Angetes Level 1

                Hi

                 

                Thanks for all the replies. I'm a relative newbie to PDF programming and learning stuff every day!

                 

                I've amended the code as suggested in reply 1 i.e.

                 

                event.change = event.change.toUpperCase(); // in the custom keystroke action

                 

                and the code below in the on blur action

                 

                var checkit = /^[A-Z]{2}$/;
                if (event.value != "")
                {

                if (checkit.test(event.value) == false)
                     {
                        app.alert("Invalid entry");
                        this.getField("text1").setFocus()
                        event.rc = false
                     }

                     else

                     {
                        this.getField("text2").setFocus()
                     }


                }

                 

                 

                You'll already know that this doesn't automate the move to the next field which brings me to my next question.

                 

                'AFMergeChange(event).length == event.target.charLimit'

                 

                Where do I actually place this code?

                 

                If I wanted to automate movement of other fields would it be the same for each field?

                 

                TIA