Skip to content

Commit 49ffc9b

Browse files
committed
Merge pull request #432 from balvig/blank_input_disable_with_bug
Disabled blank inputs don't reset on ajax submit
2 parents e677b20 + c7e5f8f commit 49ffc9b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/rails.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@
270270

271271
enableFormElement: function(element) {
272272
var method = element.is('button') ? 'html' : 'val';
273-
if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
273+
if (typeof element.data('ujs:enable-with') !== 'undefined') element[method](element.data('ujs:enable-with'));
274274
element.prop('disabled', false);
275275
},
276276

test/public/test/data-disable-with.js

+18
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ asyncTest('form input field with "data-disable-with" attribute', 7, function() {
6161
App.checkDisabledState(input, 'processing ...');
6262
});
6363

64+
asyncTest('blank form input field with "data-disable-with" attribute', 7, function() {
65+
var form = $('form[data-remote]'), input = form.find('input[type=text]');
66+
67+
input.val('');
68+
App.checkEnabledState(input, '');
69+
70+
form.bind('ajax:success', function(e, data) {
71+
setTimeout(function() {
72+
App.checkEnabledState(input, '');
73+
equal(data.params.user_name, '');
74+
start();
75+
}, 13);
76+
});
77+
form.trigger('submit');
78+
79+
App.checkDisabledState(input, 'processing ...');
80+
});
81+
6482
asyncTest('form button with "data-disable-with" attribute', 6, function() {
6583
var form = $('form[data-remote]'), button = $('<button data-disable-with="submitting ..." name="submit2">Submit</button>');
6684
form.append(button);

0 commit comments

Comments
 (0)