I am working on top of existing JavaScript (that I cannot alter) and need to check something on submit.
If my condition is true, no other submit handlers should be applied.
If my condition is false, all other submit handlers shall be applied.
What I have tried so far:
var form = jQuery('form'),
that = this,
events = $._data(form[0]).events['submit'];
form.off('submit');
form.on('submit', function (event) {
if (that.myCondition()) {
event.preventDefault();
event.stopPropagation();
return false;
} else {
console.log('Call these: ', events);
}
});
Now events
is always empty at that point.
It is empty as soon as I call form.off('submit')
and I didn't get it to work with deep cloning either.
Update: In this jsfiddle you see that both events are fired. I want one (preferably one that i add LAST) to be fired and prevent the other one from firing.