diff --git a/src/rails.js b/src/rails.js index dd58cf88..ffbc0ef0 100644 --- a/src/rails.js +++ b/src/rails.js @@ -270,7 +270,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);