-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to initialize an FieldArray? #2366
Comments
I dint get your question correctly, but see if this is what you are looking for. You can pass your custom array as a prop in FieldArray.
you can access your personal array as below in stateless fun: For push and remove, you need to provide a button in your component function and onClick either push or remove from field like hope this helps. for more details refer to the FieldArray example in redux-form documentation |
@gustavohenke @erikras I do have a question though, if I have my custom array and I want to control rendering FieldArray based on length of my custom array instead of having a button to push into fields, how would I do that? I tried to push into fields until the length of my custom array like below but my code went in infinite loop:
any thoughts??? |
@swp44744 thanks for answer. |
Hi @swp44744, your code is in infinite loop probably because
A better idea is to use some lifecycle event like |
Thank you Senhor, I will try it. But my custom array list is always going to vary based on user selection in the form which results in custom array. ComponentWillMount will render once.. Will look at other lifecycle events. Appreciate it |
@gustavohenke I think I can use |
|
Thanks for the response @erikras. I tried doing something like below:
But as FieldArray's |
This question can be closed!!! |
@swp44744 Did you ever figure this out? |
@swp44744 Yeah i wonder too, running at the same issue while init a select in FieldArray |
@Tiega91 I figured out the problem in my case. It was because I was using fields.map (also known as fields.forEeach) thinking I was actually using the plain old javascript map function but I was in fact using this http://redux-form.com/7.0.4/docs/api/FieldArray.md/#iteration I first had to use fields.getAll() to receive a regular array and then loop through it normally. In essence, if you're trying to just render your fields, it seems to me like fields.map is an easy way of doing that, but if you're trying to loop through your values to do something other than render the s in your , then make sure to use fields.getAll() |
@rodpatulski Holy Moly
haha, this should be a big warning somewhere it was also my mistake. Now i have the issue that the "input.name" is not set correct. because i used
That only works with the fields.map iterator. Do i have to create the input name manually? ########### |
Sorry for late reply... glad it worked for you.. let me know if you still have issues I will try to help. |
I found that all I had to do was
within my fields.map iterator as you said, the output of which was ''. I have run into trouble before trying to mimick the naming structure of what a outputs without actually using a as a side note. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
hi erikras,
i got an sort of datas, array object, but when i try to initialize the FieldArray, i found the FieldArray passed 'fields' props to it's component,and manage the array of fields through 'fields' ,like push() and remove() methods. so i confused, how can i passed my datas to FieldArray and initialize the component , also manage those datas using 'fields' methods(remove() and push()...etc...) ?
The text was updated successfully, but these errors were encountered: