Skip to content

Serialize form and not the children separately#1

Open
bjoern-tantau wants to merge 1 commit intomasterfrom
bjoern-tantau-patch-1
Open

Serialize form and not the children separately#1
bjoern-tantau wants to merge 1 commit intomasterfrom
bjoern-tantau-patch-1

Conversation

@bjoern-tantau
Copy link
Owner

If a form with data-remote=true is serialized elements inside fieldsets will be serialized twice if you call serializeArray on the forms children instead of on the form itself.

With the html

<form>
  <fieldset>
    <input type="text" name="foo" value="bar" />
  </fieldset>
</form>
$($('form')[0].elements).serializeArray();
// Outputs [ { name: 'foo', value: 'bar' }, { name: 'foo', value: 'bar' } ]
$($('form')[0]).serializeArray();
// Outputs [ { name: 'foo', value: 'bar' } ]

If a form with data-remote=true is serialized elements inside fieldsets will be serialized twice if you call serializeArray on the forms children instead of on the form itself.

With the html
````html
<form>
  <fieldset>
    <input type="text" name="foo" value="bar" />
  </fieldset>
</form>
````

````javascript
$($('form')[0].elements).serializeArray();
// Outputs [ { name: 'foo', value: 'bar' }, { name: 'foo', value: 'bar' } ]
$($('form')[0]).serializeArray();
// Outputs [ { name: 'foo', value: 'bar' } ]
````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant