Rendering form with array of objects
See original GitHub issueI have the following problem:
I’m trying to render multiple input fields based on index such as:
{values.education.map((item, index) => getInputFields(index))}
where values
contains an array of objects as:
education: [
{
what: '',
where: '',
description: '',
startDate: '',
endDate: ''
}
]
and getInputFields(index)
renders a set of input fields based on the education index.
The problem im running into is that if i use the default handleChange
from formik, the values
object i get is:
{
education[0].what: ''
education[0].where: '',
education[0].description: '',
education[0].startDate: '',
education[0].endDate: ''
}
So i decided to implement a custom onChange handler that uses the setFieldValue
to manually set education
. It works up to a point. Now my errors
and touched
objects are not working. Errors return the exact same object as before:
{
education[0].what: 'This field is required.'
education[0].where: 'This field is required.',
education[0].description: 'This field is required.',
education[0].startDate: '',
education[0].endDate: ''
}
Is there a special way to handle a form with an array of objects?
Will this feature be implemented anytime soon in formik?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to render an array of objects in ReactJS ? - GeeksforGeeks
How we will render an Array of Objects? We will use the map function to access each object from the array. The map()...
Read more >Render an array of objects react - Stack Overflow
When im trying to add new object console gives me this error: Uncaught Error: Objects are not valid as a React child (found:...
Read more >How to render array of objects in HTML elements ... - YouTube
How to render an array of objects in HTML element using javascript using map function (without React).
Read more >React State Array of Objects - YouTube
Learn how to use useState to keep track of arrays of objects in a react app.
Read more >How to render an array of objects with Array.map in React
The Array.map() method is key to rendering objects and data in react and it is a prototype function on all arrays in JavaScript....
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
Something similar to this would be great https://redux-form.com/7.0.4/docs/api/fieldarray.md/
my input names do use unique names
education[{index}].what
etc… it would be anot-so-elegant
solution to convert a flat list into a nested structure… but if thats the only way…if formik would use
path
instead offield
name, itd be so helpful.