Skip to content

Commit e1a8765

Browse files
committed
Prevent fieldsets from resulting in double data entries
1 parent 0c6efb6 commit e1a8765

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/rails.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
if (element.is('form')) {
116116
method = element.data('ujs:submit-button-formmethod') || element.attr('method');
117117
url = element.data('ujs:submit-button-formaction') || element.attr('action');
118-
data = $(element[0].elements).serializeArray();
118+
data = $(element[0]).serializeArray();
119119
// memoized value from clicked submit button
120120
var button = element.data('ujs:submit-button');
121121
if (button) {

test/public/test/data-remote.js

+15
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ asyncTest('submitting form with data-remote attribute', 4, function() {
155155
.trigger('submit');
156156
});
157157

158+
asyncTest('submitting form with data-remote attribute should include inputs in a fieldset only once', 3, function() {
159+
$('form[data-remote]')
160+
.append('<fieldset><input name="items[]" value="Item" /></fieldset>')
161+
.bind('ajax:success', function(e, data, status, xhr) {
162+
App.assertCallbackInvoked('ajax:success');
163+
equal(data.params.items.length, 1, 'ajax arguments should only have the item once')
164+
App.assertPostRequest(data);
165+
})
166+
.bind('ajax:complete', function() {
167+
$('form[data-remote], fieldset').remove()
168+
start()
169+
})
170+
.trigger('submit');
171+
});
172+
158173
asyncTest('submitting form with data-remote attribute submits input with matching [form] attribute', 5, function() {
159174
$('#qunit-fixture')
160175
.append($('<input type="text" name="user_data" value="value1" form="my-remote-form">'));

0 commit comments

Comments
 (0)