Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Use Enter key to navigate fields in form

    Smartclient 8.1

    I'd like to use the Enter key instead of the Tab key to navigate the form fields, how do I accomplish that?

    #2
    Hi!

    Did you find any solution for your problem?

    Comment


      #3
      See listGrid.enterKeyEditAction.

      Comment


        #4
        Is there a similar method for DynamicForm or FormItem? I'm trying to add keyPressed or keyDown handler to a form so that I can trap it and act in a custom way. Additionally, I need to catch the ESC key. Neither of the built-in key handlers seem to trap non-alpha buttons. Sorry if I missed something in the docs.
        Last edited by ls3674; 15 Jun 2012, 08:30.

        Comment


          #5
          Several different APIs possibly apply. Could you explain your use case in more detail - what are the specific keypresses, what needs to happen on these keypresses, where is the keyboard focus when the keys are pressed..

          Comment


            #6
            Sure thing.

            I'm glad you asked about form focus, because I have tried a few things there unsuccessfully, which I'll get to shortly.

            Use case: A small form is presented to the user, that sits inside a Window object. The form has two TextInputs, and one CheckboxItem. Under the form are a cancel button and a save button.

            I want to intercept the enter button click and perform the same action that I have the button clicked handler performing for the save button.

            I want to intercept the escape button press to close the form if the decide that they don't want to continue the action.

            With regard to focus, I was going to put this in another thread, however it's related so I'll put it here.

            I wanted the focus to go to the second TextItem in the form, so I overrode the onInit for the Window object in this way- this also represents what I'd like to do with the escape button press

            Code:
            @Override
                protected void onInit()
                {
                    dfIPPort.focusInItem("tiPort");
                    this.addKeyPressHandler(new KeyPressHandler()
                    {
                        @Override
                        public void onKeyPress(KeyPressEvent keyPressEvent)
                        {
                            SC.say(keyPressEvent.getKeyName());
                            if(keyPressEvent.getKeyName().equals("escape"))
                            {
                                destroy();
                            }
                        }
                    });
                }

            Comment


              #7
              The form has built-in support for an Enter keypress triggering something - set dynamicForm.saveOnEnter then add a SubmitValuesHandler if you need to do something other than a normal save.

              You should be able to pick up Escape by just adding a keyPress handler to the form as a whole, however, bear in mind that Enter has meaning within certain items (TextArea) and Escape can mean "undo changes" on some platforms. It's not certain the native input controls will allow these key events to bubble on all platforms.

              Your approach for setting focus seems fine.. are you having trouble with that?

              Comment


                #8
                Thanks,

                Your comments about the escape key most likely explain why it's not being picked up- That is, my keyPressedHandler and another (not shown in previous code) keyDownHandler does not pick up the escape key. The only keys I seem to get reliable hits on are the alpha keys. When I say reliable, I mean, for example, I can't pick up the escape key on either of the key events, but for some reason pressing escape quickly, twice causes a Window object to close.

                I am having trouble with the focus setting. I expect it to go to a FormItem after the form is inited, but it does not have focus. Is onInit the wrong place to put something like that? Is something possibly being called later that would remove that focus?

                Comment


                  #9
                  Actually you are in browser-dependent bugs territory here. When it comes to special keys, browsers are extremely inconsistent as to whether they provide no keyDown event, a keyDown event but no keyPress event, or the whole series. Also, this differs according to where keyboard focus is.

                  We make heroic efforts to ensure that no matter what the browser does, we always give you a keyPress event, however if the browser does not fire keyDown at all, there's no way to synthesize it. So use keyPress in general unless you have compelling reasons.

                  Comment

                  Working...
                  X