4 Replies Latest reply on Feb 8, 2012 8:41 AM by Pyrdacor

    Textbox + Button (Check for Return-Keystroke)

    Pyrdacor

      Hi I have an Acrobat Form with a textbox and a button. If the button is pressed the search-plugin will be started searching for the text entered in the textbox in the index. This all works fine.

       

       

      Now I want to realize the following behavior:

       

      If the user enters a text and hits the Return-Key the search shall also start like if the button was pressed. I also realized this by using the keystroke- and the validate-events of the textbox field and checking if the commitKey is equal to 2.

       

       

      But here is the problem:

       

      When I leave the textbox (loses focus) and re-enter it and then I hit the Return-Key nothing happens. There is no keystroke or validate event at all when the text in the textbox was not changed but I want to re-enable a search after closing the search-window with the same text. And also there are a few checkboxes that indicates the language that should be used (different folders on the HDD). So if only the languages change but not the text in the textbox, the Return-Key will not be detected and so the functionality is bugged.

       

      Has someone an idea how I can realize that? Basically I only need to know how I can determine a Return-Keystroke or Textbox-Validation when the text in the textbox has not been changed.

       

       

      Thanks for help.

        • 1. Re: Textbox + Button (Check for Return-Keystroke)
          try67 MVP & Adobe Community Professional

          If the text-box is not set as a multiline box, pressing Enter will not

          trigger any validation event because it is not an accepted input.

          The same goes for entering and exiting the box without making any changes

          to it.

          What you could possibly do is set your box as a multiline box, so that

          pressing enter will trigger the event you want to use, but then use the

          validation script to reject that value.

          1 person found this helpful
          • 2. Re: Textbox + Button (Check for Return-Keystroke)
            Pyrdacor Level 1

            This would be an alternative but multiline textboxes have a scrollbar next to them which I don't want to be visible. Is there a possibility to hide/disable it?

             

            And how can I check for the enter-key input? I know the commitKey property of the event structure but I can't find something that just specifies the current keycode that caused the keystroke event.

             

             

            Is there a possibility to check for global form keystroke events? Or something like a default-button behavior. Because basically this is what I want and I guess this is a common form behavior that should be supported by the Acrobat JS API.

            • 3. Re: Textbox + Button (Check for Return-Keystroke)
              try67 MVP & Adobe Community Professional

              Multiline text fields don't have a scroll bar by default, only when the length of the text is longer than the size of the box.

               

              You can use the following code (as the custom keystroke code) to reject an Enter keystroke (and perform some action when it is detected):

               

              if (event.change.charCodeAt(0)==10) {

              // The user pressed Enter... do something

              event.rc = false

              } else event.rc = true;

               

              It's not possible to define a global form kestroke event, but it is possible to place the code in a doc-level function and then call that function from all of the fields in which you want to apply this validation.

              1 person found this helpful
              • 4. Re: Textbox + Button (Check for Return-Keystroke)
                Pyrdacor Level 1

                The textbox is very small (like a one-line textbox) and there is a scrollbar next to it even if it is empty. I use Acrobat 9.0. I talk about a vertical scroll bar not the horizontal one which would be ok for long texts.

                 

                Thanks for the event code example. I will try this out.

                 

                Edit: Another problem is the fact that long texts in a multi-line textbox will not lead to a horizontal scrolling anymore but in a newline and a vertical scroll. This is not the desired behavior.

                The logic with enter-key now works fine but the appearance of the textbox is very unpleasant.