fix(Form): Form doesn't serialize array form fields
See original GitHub issueSteps to Reproduce
- Build a form with array name fields (data[one], data[two])
<Form.Input name="data[one]"></Form.Input>
<Form.Input name="data[two]"></Form.Input>
Expected Form should serialize those fields into a single object
formData: {
data: {
one: 'value',
two: 'value'
}
}
Result Form does this:
formData : {
data[one]: 'value',
data[two]: 'value'
}
Testcase http://codepen.io/anon/pen/VmxEKQ (see output in console)
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
`serializeArray()` not getting all fields - Stack Overflow
You haven't given the email and password inputs proper names, that's why the are excluded from the serialization. Give those input elements ......
Read more >Ignoring empty form fields · Issue #28 - GitHub
As far as I could understand, there is no way to ignore empty form fields, excluding them from the resulting object.
Read more >.serialize() | jQuery API Documentation
In this case, jQuery serializes the successful controls within the form. Only form elements are examined for inputs they contain, in all other...
Read more >serialize - Manual - PHP
I was trying to submit a serialized array through a hidden form field using POST and was having a lot of trouble with...
Read more >How to Convert HTML Form Field Values to a JSON Object
The FormData API doesn't directly convert form values to JSON, but we can get there by using the entries method and passing its...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
All form serialization and validation will be accomplished using the controlled component pattern where the value of each form control is captured and placed in state somewhere, probably a higher order form component. You can refer to react-reformed for some ideas.
We’ll likely bake something like this into SUIR and attempt to simplify the API and usage a bit to reduce the workload of wiring this up.
So, in that case, instead of using the
name
attribute in the DOM to find values and serialize them, your virtual DOM change handlers will be placing the value in the correct place in the form’s state model. This is preferred since the data is then handled inside of React, instead of the browser’s real DOM. Aside from the fact that using the real DOM is an antipattern, using React’s virtual DOM makes testing a breeze, keeps the app fast, and is better for integrating other tools like validation and local storage.You might also find some of these other react form libraries helpful: https://github.com/erikras/redux-form/ https://github.com/christianalfoni/formsy-react https://github.com/prometheusresearch/react-forms
Cheers!
Glad to hear it 😃