Bind and unbind a submit event : JS error on unload

Bind and unbind a submit event : JS error on unload

Hi,

I have one global JS file that bind to the submit event of every form a function disabling each submit button.

Sometimes, i don't want the submit button to be disabled because a click from the user results in the download of a dynamically generated file, which means that the page doesn't change at all and the user just needs to be able to submit the form one more time.

That's why i added in a other JS file loaded after the first one, a piece of code to unbind the event. It goes like this :

  1. /* Global JS File */
  2. $(document).ready(function(){
  3.         $('form').bind('submit.disable', function() {...});
  4. });
  1. /* Second JS File */
  2. $(document).ready(function(){

  3.         $('form').unbind('submit.disable');
  4. });

It's working fine, the only things is that when i click the submit button, i got a Jquery error on line 1919. The job's is done but i get the error.

I fixed it that way :
  1. - var events = jQuery.data(this, "events"), handlers = events[ event.type ];
  2. + var events = jQuery.data(this, "events") || {}, handlers = events[ event.type ];
I don't know if it's the best way to fix it, maybe it's hidding a much bigger problem, but it's working, i just let you guys do whatever you want with it.

Best regards.