Skip to content

Commit

Permalink
Merge pull request #432 from balvig/blank_input_disable_with_bug
Browse files Browse the repository at this point in the history
Disabled blank inputs don't reset on ajax submit
  • Loading branch information
rafaelfranca committed Sep 1, 2015
2 parents e677b20 + c7e5f8f commit 49ffc9b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rails.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

Expand Down
18 changes: 18 additions & 0 deletions test/public/test/data-disable-with.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<button data-disable-with="submitting ..." name="submit2">Submit</button>');
form.append(button);
Expand Down

0 comments on commit 49ffc9b

Please sign in to comment.