Entering text into a TextBox in the google web toolkit in Firefox calls the submit form, but not IE

gwt 1.6.4 ie 8 ff 3.6.13

My users want to be able to press Enter to submit the form in the gwt text box. So I wrote the code, got it working, and then found that it was sent twice (in firefox). So I took it and noticed that getting into firefox caused the page to be sent, but in IE it is not.

So either I have half the work (one of two popular browsers), or it works in ie and double is sent to firefox.

Suggestions? I saw a lot of comments about this, but nothing specific to gwt.

+3
source share
2 answers
input.addKeyPressHandler(new KeyPressHandler()
            {
                @Override
                public void onKeyPress(KeyPressEvent event_)
                {
                    boolean enterPressed = KeyCodes.KEY_ENTER == event_
                            .getNativeEvent().getKeyCode();
                    if (enterPressed)
                    {
                        //submit logic here
                    }
                }
            });
+6
source

, , submit on enter, , enter , . , . , , FocusWidget, .

protected final KeyPressHandler submitOnEnterHandler = new KeyPressHandler()
    {
        @Override
        public void onKeyPress(KeyPressEvent event)
        {
            char charCode = event.getCharCode();
            if (submitOnEnter && (charCode == '\n' || charCode == '\r'))
            {
                final Object source = event.getSource();
                final String beforeText;
                if (source instanceof TextBoxBase)
                    beforeText = ((TextBoxBase) source).getText();
                else
                    beforeText = null;
                Scheduler.get().scheduleDeferred(new ScheduledCommand()
                {
                    @Override
                    public void execute()
                    {
                        String afterText;
                        if (source instanceof TextBoxBase)
                            afterText = ((TextBoxBase) source).getText();
                        else
                            afterText = null;
                        if (beforeText.equals(afterText))
                            submit();
                    }
                });
            }
        }
    };
+1

All Articles