我想知道如何监听TextField
. 我需要拦截这些事件以进行价值检查。
我写了一个扩展TextBox
,它触发了TextChangeEvents
。但是当我将文本放入文本字段时,我没有收到对该onBrowserEvent(Event event)
方法的调用。
有什么提示吗?
public class ExtendedTextBox extends TextBox {
/**
* Creates an empty extended text box.
*/
public ExtendedTextBox() {
super();
// Catch the browser events.
sinkEvents(Event.ONKEYUP);
sinkEvents(Event.ONPASTE);
}
@Override
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
System.out.println(event.getTypeInt());
switch (event.getTypeInt()) {
case Event.ONKEYUP:
case Event.ONPASTE: {
// Fire the event after the text box shows the new data.
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
fireEvent(new TextChangeEvent(ExtendedTextBox.this.getText()));
}
});
break;
}
default:
}
}
/**
* Add a given {@link TextChangeEventHandler} to the widget.
*
* @param handler
* the handler
* @return {@link HandlerRegistration} used to remove the handler
*/
public HandlerRegistration addTextChangeEventHandler(TextChangeEventHandler handler) {
return addHandler(handler, TextChangeEvent.TYPE);
}
}