Permalink
Browse files

Merge pull request #2646 from arian/fix-2645-form-submit-delegation

Fix 2645 form submit delegation
  • Loading branch information...
ibolmo committed Aug 27, 2014
2 parents a171806 + 98e1fc6 commit d2fc72bc9ff2f063e011d4c7b0b4b90452b35301
Showing with 37 additions and 1 deletion.
  1. +6 −1 Source/Element/Element.Delegation.js
  2. +31 −0 Specs/Element/Element.Delegation.js
@@ -57,7 +57,12 @@ var formObserver = function(type){
remove: function(self, uid){
var list = self.retrieve(_key + type + 'listeners', {})[uid];
if (list && list.forms) for (var i = list.forms.length; i--;){
list.forms[i].removeEvent(type, list.fns[i]);
// the form may have been destroyed, so it won't have the
// removeEvent method anymore. In that case the event was
// removed as well.
if (list.forms[i].removeEvent){
list.forms[i].removeEvent(type, list.fns[i]);
}
}
},
@@ -54,4 +54,35 @@ describe('Element.Delegation', function(){
});
describe('removeEvent', function(){
describe('submit', function(){
it('should remove nicely', function(){
var element = new Element('div', {
html: '<div><form><input type="text"></form></div>'
});
var input = element.getElement('input');
var listener = function(){};
element.addEvent('submit:relay(form)', listener);
// IE8, fireEvent on the observer element. This adds the
// submit event to the <form> element.
element.fireEvent('focusin', [{target: input}, input]);
// remove element, which also removes the form
element.getElement('div').destroy();
// now removing the event, should remove the submit event from the
// form, but it's not there anymore, so it may not throw an error.
element.removeEvent('submit:relay(form)', listener);
});
});
});
});

0 comments on commit d2fc72b

Please sign in to comment.