-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have textbox and method which listens two events.
<textbox id="test" />
@Listen("onOK = #test; onBlur = #test")
public void action(Event event) {
// do something ...
}
When I press Enter on the Textbox, the event "onOK " is triggered. It's OK. But then when I lose focus from the Texbox the event "onBlur" is triggered too. It's bad, because in that case my method "action" is called two times. How can I cancel this second event ?
The issue is the 2 events, onOK
and onBlur
, have different meaning but invoke the same listener. This is not a usual case. Maybe you should separate action()
into 2 different listeners.
You could add a boolean flag.
boolean finished= false;
private void method1() {
if (!finished) {
//...
finished= true;
}
}
private void method2() {
if (!finished) {
//...
finished= true;
}
}
Another option could be to stop the event propagation => #stopPropagation()
Asked: 2016-05-25 06:07:16 +0800
Seen: 21 times
Last updated: May 27 '16