From fa94bf0b4b33d5cc225ae538115e275a830ed304 Mon Sep 17 00:00:00 2001 From: arojoal Date: Fri, 1 Nov 2013 22:26:33 +0100 Subject: [PATCH] Refs https://github.com/rails/jquery-ujs/issues/338 Using jquery-remotipart I've got some strange behaviour that could be avoided by doing a little change in disableFormElement function. The problem occurs when this function gets called a second time when the submit button has already been disabled. When this happens, it is not possible to get the original text show at the button when it is enabled back since the "ujs-enabla-with" attribute has been overwritten with the "disabled-with" text in the second call to the disableFormElement. I wonder if this function shouldn't check if ujs-enable-with already exists and, in that case, don't overwrite it. --- src/rails.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rails.js b/src/rails.js index 4659b03c..eceb7ee6 100644 --- a/src/rails.js +++ b/src/rails.js @@ -184,7 +184,7 @@ disableFormElements: function(form) { form.find(rails.disableSelector).each(function() { var element = $(this), method = element.is('button') ? 'html' : 'val'; - element.data('ujs:enable-with', element[method]()); + if (!element.data('ujs:enable-with')) element.data('ujs:enable-with', element[method]()); element[method](element.data('disable-with')); element.prop('disabled', true); }); @@ -197,7 +197,10 @@ enableFormElements: function(form) { form.find(rails.enableSelector).each(function() { var element = $(this), method = element.is('button') ? 'html' : 'val'; - if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with')); + if (element.data('ujs:enable-with')){ + element[method](element.data('ujs:enable-with')); + element.data('ujs:enable-with', null); + } element.prop('disabled', false); }); },