itemBox.addKeyUpHandler( new KeyUpHandler()
{
public void onKeyUp( KeyUpEvent event )
{
String currentValue = itemBox.getValue().trim();
// handle backspace
if( event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE )
{
if( "".equals( currentValue ) )
{
doTheJob( );
}
}
}
} );
Expect behavior:
when the textbox is empty, then i hit delete, will run doTheJob();
Current behavior:
when there is one character, i hit delete, it will trigger doTheJob();
In other word, is there any way i can get textbox content before i hit delete key?
I tried to used a var to hold the last value, but it needs to register another listener and the impl is not so effective.
Thanks for your input.
////////////////////Edit //////////////////////
use KeyDownHandler did solve the above problem, however lead to another problem:
i use itemBox.setValue( “” ); to clear the textbox but it will always have a comma there.
itemBox.addKeyDownHandler( new KeyDownHandler()
{
public void onKeyDown( KeyDownEvent event )
{
// handle backspace
if( event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE )
{
String currentValue = itemBox.getValue().trim();
if( "".equals( currentValue ) )
{
doTheJob();
}
}
// handle comma
else if( event.getNativeKeyCode() == 188 )
{
doOtherJob();
//clear TextBox for new input
itemBox.setValue( "" );
itemBox.setFocus( setFocus );
}
}
} );
after
prevent event bubbling with
So the event will be canceled before comma is added to the textbox content.