jQuery event trigger - cancelable event
Posted
by
Dismissile
on Stack Overflow
See other posts from Stack Overflow
or by Dismissile
Published on 2012-12-18T17:01:47Z
Indexed on
2012/12/18
17:03 UTC
Read the original article
Hit count: 267
jQuery
|jquery-events
I have created a jquery plugin which is triggering an event:
$.fn.myplugin = function(options) {
this.on("foo.myplugin", options.foo);
this.on("bar.myplugin", options.bar);
};
I want to check if foo has been canceled by a user and prevent bar from being triggered:
// trigger foo
this.trigger("foo.myplugin");
// how do I check if foo was canceled
if( !fooCanceled ) {
this.trigger("bar.myplugin");
}
How can I check if foo was canceled to prevent bar from being triggered?
jQuery UI does something similar to this, but it did not work when I tried:
if (this._trigger("search", event) === false) {
return;
}
I tried something similar to this:
if( this.trigger("foo.myplugin") === false ) {
return;
}
this.trigger("bar.myplugin");
But bar was still being triggered.
© Stack Overflow or respective owner