Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to override/remove default handler in GWT widget?
    text
    copied!<p>I would like to change a behavior of SuggestBox in GWT. I want submit value by pressing ENTER. However the SuggestBox have a KeyHandler, which catches any enter key and sets a new Selection. I am looking for a solution to remove/overide this Handler.</p> <p>This method is called by constructor in SuggestBox</p> <pre><code>private void addEventsToTextBox() { class TextBoxEvents extends HandlesAllKeyEvents implements ValueChangeHandler&lt;String&gt; { public void onKeyDown(KeyDownEvent event) { switch (event.getNativeKeyCode()) { case KeyCodes.KEY_DOWN: display.moveSelectionDown(); break; case KeyCodes.KEY_UP: display.moveSelectionUp(); break; case KeyCodes.KEY_ENTER: case KeyCodes.KEY_TAB: Suggestion suggestion = display.getCurrentSelection(); if (suggestion == null) { display.hideSuggestions(); } else { setNewSelection(suggestion); } break; } delegateEvent(SuggestBox.this, event); } public void onKeyPress(KeyPressEvent event) { delegateEvent(SuggestBox.this, event); } public void onKeyUp(KeyUpEvent event) { // After every user key input, refresh the popup's suggestions. refreshSuggestions(); delegateEvent(SuggestBox.this, event); } public void onValueChange(ValueChangeEvent&lt;String&gt; event) { delegateEvent(SuggestBox.this, event); } } TextBoxEvents events = new TextBoxEvents(); events.addKeyHandlersTo(box); box.addValueChangeHandler(events); </code></pre> <p>}</p> <p>Is it possible to remove this Handler from box by using HandlerRegistration? Is there any nice solution by extending class and overriding private method?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload