Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/rails.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@
method = element.data('method');
url = element.data('url');
data = element.serialize();
if (element.is('input[type=checkbox],input[type=radio]')) {
data = element.attr('name') + '=0&' + data;
}
if (element.data('params')) data = data + '&' + element.data('params');
} else if (element.is(rails.buttonClickSelector)) {
method = element.data('method') || 'get';
Expand Down
28 changes: 28 additions & 0 deletions test/public/test/data-remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,34 @@ asyncTest('changing a select option with data-remote attribute', 5, function() {
.trigger('change');
});

asyncTest('submitting an unchecked checkbox with data-remote attribute submits input with value 0', 3, function () {
$('#qunit-fixture')
.append($('<input type="checkbox" name="user[active]" value="1" data-remote="true" data-url="/echo">'));

$('input[type="checkbox"][data-remote]')
.on('ajax:success', function (e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success');
App.assertRequestPath(data, '/echo');
equal(data.params.user.active, '0', 'ajax arguments should have key active with value 0');
})
.on('ajax:complete', function () { start() })
.trigger('change');
})

asyncTest('submitting an unchecked radio button with data-remote attribute submits input with value 0', 3, function () {
$('#qunit-fixture')
.append($('<input type="radio" name="user[active]" value="1" data-remote="true" data-url="/echo">'));

$('input[type="radio"][data-remote]')
.on('ajax:success', function (e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success');
App.assertRequestPath(data, '/echo');
equal(data.params.user.active, '0', 'ajax arguments should have key active with value 0');
})
.on('ajax:complete', function () { start() })
.trigger('change');
})

asyncTest('submitting form with data-remote attribute', 4, function() {
$('form[data-remote]')
.on('ajax:success', function(e, data, status, xhr) {
Expand Down