Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT TextBox - Notification of value changes during editing

Tags:

java

gwt

I have a TextBox on a Panel and I want to be notified when the value of the 'TextBox' changes.

I have tried the following event handlers:

  • ChangeHandler
  • ValueChangeHandler
  • KeyPresshandler

My problem is that the ValueChangeHandler and ChangeHandler only fire when the focus leaves the controls. The KeyPressHandler fires correctly, but before the TextBox itself has seen the event, which means that a call to getText() from my event handler sees a stale value.

Is there an event that would work exactly like KeyPressHandler but be fired after the TextBox has seen the event?

EDIT: this behaviour is seen in Chrome and IE8 on Windows XP

like image 607
David Sykes Avatar asked May 11 '10 07:05

David Sykes


2 Answers

Try the KeyUpHandler.

like image 189
Chris Boesing Avatar answered Nov 01 '22 05:11

Chris Boesing


A very robust (though not very elegant) solution which catches ALL changes including copy/pasty via mouse or text suggestions inserted via a virtual keyboard (e. g. such as the ios 8 keyboard) is to start a timer on focus and to check the value of the textbox in an appropriate time interval. The timer is stopped on blur (don't forget to do a final check on blur).

I am not aware of any "handler-based" solution to catch all textbox changes.

like image 2
Sir Hackalot Avatar answered Nov 01 '22 06:11

Sir Hackalot