Skip to content

Commit

Permalink
Merge pull request #461 from abuisman/master
Browse files Browse the repository at this point in the history
Prevent fieldsets from resulting in double data entries
  • Loading branch information
rafaelfranca committed Feb 26, 2016
2 parents b0bd907 + e1a8765 commit 72ca4f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rails.js
Expand Up @@ -115,7 +115,7 @@
if (element.is('form')) {
method = element.data('ujs:submit-button-formmethod') || element.attr('method');
url = element.data('ujs:submit-button-formaction') || element.attr('action');
data = $(element[0].elements).serializeArray();
data = $(element[0]).serializeArray();
// memoized value from clicked submit button
var button = element.data('ujs:submit-button');
if (button) {
Expand Down
15 changes: 15 additions & 0 deletions test/public/test/data-remote.js
Expand Up @@ -155,6 +155,21 @@ asyncTest('submitting form with data-remote attribute', 4, function() {
.trigger('submit');
});

asyncTest('submitting form with data-remote attribute should include inputs in a fieldset only once', 3, function() {
$('form[data-remote]')
.append('<fieldset><input name="items[]" value="Item" /></fieldset>')
.bind('ajax:success', function(e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success');
equal(data.params.items.length, 1, 'ajax arguments should only have the item once')
App.assertPostRequest(data);
})
.bind('ajax:complete', function() {
$('form[data-remote], fieldset').remove()
start()
})
.trigger('submit');
});

asyncTest('submitting form with data-remote attribute submits input with matching [form] attribute', 5, function() {
$('#qunit-fixture')
.append($('<input type="text" name="user_data" value="value1" form="my-remote-form">'));
Expand Down

0 comments on commit 72ca4f1

Please sign in to comment.