5 Replies Latest reply on Dec 31, 2012 1:19 PM by topsykrett06

    Save last character in autotab script?

    topsykrett06

      Hi,

       

      I'm new to javascript and i've been working with a form I was given. The one part of the form consists of 3 text fields, one on top of the other, effectively making that part of the form like lined paper. Anyhow, I need to implement an autotab script so that when the user reaches the end of the textfield, it will go right onto the next texfield. I had found the adobe documentation on the fieldFull event so I am working off of that. This is the example:

       

       

      if ( event.fieldFull )  

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

       

       

       

      I have that as a custom keystroke script with my textfield names and it works fine, except for the fact that the last character before the tab is lost. I have tried many things but my knowledge of the systax and fuctions isn't very good. I just need a way to save that last character and get it on the next textfield. Can anyone help out? (Also, it might be helpful to note that I cannot change the design of the form and I am not using LiveCycle).

       

       

      Thanks!

        • 1. Re: Save last character in autotab script?
          George_Johnson MVP & Adobe Community Professional

          I've never seen that type of thing done well, but the technique demonstrated with the following works just fine: https://workspaces.acrobat.com/?d=AG6oZ3bi3DYHokxDPeWN7A

           

          Study the scripts attached to various field events to see how it works. The lines will show if the field is blank, but obscured otherwise. The purpose of such lines is to help when hand-filling and they will be available when a blank form is printed.

           

          This doesn't work if the first line is shorter than the subsequent ones if they layout is something like:

           

           

          Description: [ this is the first line        ]

          [ this is the second line                         ]

          [ this is the third line                             ]

           

          But you can sometimes place the field below the first one and still have sufficient space.

          • 2. Re: Save last character in autotab script?
            gkaiseril MVP & Adobe Community Professional

            That is only part of the script. You are working within the keystroke field prior to commitment of the keystroke. So you need to validate the last entered key and then the length of the previous entered key strokes, event.value, and the current key stroke to the character limit of the field.

             

            See JavaScript - setFocus Method for tabbing to next form field for a working example for a numberic field.

             

            Document level JavaScirpt used to test entry of a numeric value

             

            function AutoTab(doc, event, cNext)

            {

            // Call the built-in routine to allow numbers only.

            AFNumber_Keystroke(0, 0, 0, 0, "", true);

            // If we've filled in the field completely, jump to the next one.

            if (event.rc && AFMergeChange(event).length == event.target.charLimit)

              doc.getField(cNext).setFocus();

            }

             

            The keystroke for each field is:

             

            var oDoc = this; // object being processed

            var oObject = event; /./ event being processed

            var cNextField = "SSN.1"; // next field when current field is full

            AutoTab(oDoc, oObject, cNextField);

            • 3. Re: Save last character in autotab script?
              topsykrett06 Level 1

              I see. Unfortunately the part of the form is designed exactly as you had stated:

              Description: [ this is the first line        ]

              [ this is the second line                         ]

              [ this is the third line                             ]

               

               

              I was hoping there was some way to maybe take in the last letter from the input as a char and just use it as output in the next text field (something like that.. maybe use charAt() if the data in the textfield can be saved as a string), but all of my googling and reading documentation hasn't turned up any terribly useful syntax. I appreciate the response though, I will see what I figure out for it. May try a combination of your suggestion and using a predefined amount of characters for the first line. Thank you for the response

              • 4. Re: Save last character in autotab script?
                George_Johnson MVP & Adobe Community Professional

                There are a number of problems with trying to approach this as you described initially, even if you could get the last character, including words would get split in the middle (against user's expectations), the backspace key won't work as expected when going from one field to the other, and a number of other problems. Unfortunately, I'm not aware of a satisfying alternative as long as you're limited to such a layout.

                • 5. Re: Save last character in autotab script?
                  topsykrett06 Level 1

                  Well I was thinking of trying to use a while loop, taking in each character. Then when event.fieldFull is true, send the last character to the next text field. Or using a similar approach with an array of characters. Just kind of thinking out loud here, probably completely off.. not even sure what is possible with how user input works with text fields. Anyway, thanks to you both for suggestions. I'll keep digging and use what you've told me to try and come up with something. I'm now thinking this is kind of a tall order without being able to change the form layout.