From c7e5f8f59db7e37410610658b7c3f1652fc01cbb Mon Sep 17 00:00:00 2001 From: Jens Balvig Date: Thu, 9 Jul 2015 09:41:39 +0200 Subject: [PATCH] Disabled blank inputs didn't reset on ajax submit Submitting a remote form with a blank input using [data-disable-with] would cause the disable-with message to get stuck since if("") == false --- src/rails.js | 2 +- test/public/test/data-disable-with.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/rails.js b/src/rails.js index 2dc31e30..7feda212 100644 --- a/src/rails.js +++ b/src/rails.js @@ -266,7 +266,7 @@ enableFormElement: function(element) { var method = element.is('button') ? 'html' : 'val'; - if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with')); + if (typeof element.data('ujs:enable-with') !== 'undefined') element[method](element.data('ujs:enable-with')); element.prop('disabled', false); }, diff --git a/test/public/test/data-disable-with.js b/test/public/test/data-disable-with.js index 5e2a67da..0366f81e 100644 --- a/test/public/test/data-disable-with.js +++ b/test/public/test/data-disable-with.js @@ -61,6 +61,24 @@ asyncTest('form input field with "data-disable-with" attribute', 7, function() { App.checkDisabledState(input, 'processing ...'); }); +asyncTest('blank form input field with "data-disable-with" attribute', 7, function() { + var form = $('form[data-remote]'), input = form.find('input[type=text]'); + + input.val(''); + App.checkEnabledState(input, ''); + + form.bind('ajax:success', function(e, data) { + setTimeout(function() { + App.checkEnabledState(input, ''); + equal(data.params.user_name, ''); + start(); + }, 13); + }); + form.trigger('submit'); + + App.checkDisabledState(input, 'processing ...'); +}); + asyncTest('form button with "data-disable-with" attribute', 6, function() { var form = $('form[data-remote]'), button = $(''); form.append(button);