PDA

View Full Version : Field Change Listener



mbgold78
13 Aug 2010, 5:10 AM
Hello
Im trying to disable a button when a TextField is blank, see the below snippet, except the button does not grey until the textfield loses focus, even though the button is not clickable. How can I achieve the visual disable/enable without loses the field focus?

field.addListener(Events.Change, new Listener<FieldEvent>() {

@Override

public void handleEvent(FieldEvent be) {
String value = (String) be.getValue();
if (value != null && !value.isEmpty()) {
button.enable();
} else {
button.disable();
}

}
});

sven
13 Aug 2010, 5:12 AM
The change event only fires onblur. You can for example add a timer that checks the field every few milliseconds for its value. Or you can add some keylistener that check if the field got cleared or not.