1

I have a remote_form_for. Now :onclick I want to disable the submit button and on ajax:complete I want to enable the buttons back.

:onclick disable is working fine, but enable it back using ajax:complete event is not working.

Any thoughts?

Here comes the code,

(function(jQuery){
    jQuery.fn.disableWith = function(options){
        var settings = jQuery.extend({
            disable_event : function(e){
                e.preventDefault();
                return false;
            }
        }, options);

    this.bind('click', function(){
        jQuery(this).click(settings.disable_event);
    });
    this.bind("ajax:complete", function(){
        jQuery(this).unbind('click', settings.disable_event);
    });

    return this;
    };
})(jQuery);
Souman Mandal
  • 115
  • 1
  • 8

1 Answers1

0

You are using the wrong event - try ajaxComplete :

this.bind("ajaxComplete", function(){
    jQuery(this).unbind('click', settings.disable_event);
});

Docs on Ajax Events

Manse
  • 37,765
  • 10
  • 83
  • 108
  • if you put an `alert();` or `console.log()` in the event function - is the event even firing ? – Manse Feb 13 '12 at 10:04
  • It is not going inside the event. So alert(); or console.log() is not giving any output. If I submit the form using jquery ajax function call **"ajaxComplete"** is working fine. – Souman Mandal Feb 13 '12 at 13:06