-
-
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
Multiple forms on page #28
Comments
I like this library a lot. Unfortunately without this I cannot use it for all forms in my app. |
My ideas about API: createFormReducerContainer(
'sliceName',
id => createFormReducer(id, ['field1', 'field2'])
)
@connect((state, props) => ({form: state.sliceName.get(props.itemId)}))
@reduxForm(props => ['sliceName', props.itemId], validationFunction)
class FormComponent {} Something like that. Maybe you can come with something better. |
This is an important question. I'm thinking about it, not ignoring you. 😄 💭 |
I think that the answer is that Redux isn't very good at this yet. It would be nice to be able to asynchronously load your list of objects, and then dynamically add/merge your reducers to the store. fetchRecords()
.then(records => {
reducers = {};
records.forEach(record => {
reducers[record.id] = createFormReducer(`widgets.${record.id}`, ['name', 'price']);
});
store.addReducers({
widgets: reducers
}); // merges this object into the master reducer
}); Obviously, you'd then want to clean up with some sort of @gaearon, is dynamic reducer mutation eventually going to be supported for applications apart from hot reloading? @janmarek is not the first to request this. |
You don't need multiple reducers. Just the one you have needs to take care for multiple data instances. |
Sure, but redux-form, in its current state is designed to operate on a single flat object of fields. If you make that object deeper and full of other objects, both the reducer and the validation get much more complicated. I think you're right in that they could both be wrapped in some other function that handled the multiplicity and let the original reducer and validation do their one-object jobs. |
Wow. So the solution resulted in a surprisingly simple API. See Editing Multiple Records. |
Thank you sir :) |
You can see it in action here. If it fails to load, keep hitting reload. it's a feature! |
Editing Multiple Records link no longer working and can't find it in the current repo so just adding a short snippet for others running into same issue. Basically, just use
That will make the form reducer use that so you don't get collisions. |
So this all works for me - but what is the name/label of one instance of a form? I have a page that displays multiple pieces of furniture. Each piece has an 'edit' form. They're all instances of our UpdateFurnitureForm. I'm passing a unique formKey to each one, so the forms maintain data independently. The forms work exactly as intended. (Thanks for all the helpful advice above!) Now I'd like to programmatically change the value of one of the form fields. I already have that working on another page, on a form that is a unique form (i.e., not an instance of a set of duplicate forms). I used instructions from this comment to get that working properly. See my comment in that thread for my working code. So for the instance of one of the multiple forms, what label should I use? The
|
Here's the reference to the multiple records example in the v5.x docs. Anyone know how / if to support this in v6? |
@steakchaser The way you do that in v6 is to change the <MyRecord form={`record[${record.id}]}/> |
Hi @erikras - Im trying to setup dynamic form names, do I need to setup the formName in any special manner if Im using the code from above?
Do I need to map props? |
@jrutter maybe this helps: http://stackoverflow.com/a/37464048/2619107. |
How would this work with |
Hi @brianium did you find a solution to this as I have the same problem? |
@cashkows-jason my solution was to create a container that could pass a selector function or selected values themselves. It is a little clunky in that it requires a container where you may otherwise not have one, but other than that it worked nicely |
Hey guys may I ask where is this documented in v6? I tried modeling after http://redux-form.com/5.3.3/#/examples/multirecord?_k=kcy5ns and found out that version 6 doesn't require a fields option as mentioned in this SO post http://stackoverflow.com/a/37464048/2619107. |
@erikras please help, how can we use your solution with |
@erikras I want to use multiple forms like selectingFormValues on the same page. I'm going to pass form name using props like this:
But how should I pass form name to this line of your example: If I don't know the form name? The problem is I should have the few same forms on the same page and I should get their values on any update (not on submit). I see you have |
I used redux-form v6 and followed this instruction: http://stackoverflow.com/a/37464048/2619107 and it worked |
@anhtran1906 that worked seamlessly for me too. Thanks for the link. |
It's a somewhat more complicated problem than issue #28. I want to have multiple forms in one component. In the parent component, I use form={...} and initialVlaues={...} to pass in initial values for each form. It works as the solutions in the above posts suggested. However, this works only if I do not connect the child component to redux store. For example, the code below works:
However, if I am trying to connect the component to redux store, like below:
It stops working. The initial values for all forms will be the initial values of the last form. I tried using ownProps, without luck:
Can anyone suggest what the problem is, or a solution? |
@willshu2049 2 things that may help you... Bug In redux Form (I think?)
which appears to be a bug, but not sure if anyone else is experiencing this (redufx-form v7.0.4) Any thoughts @erikras? Solution hack...
Dynamic generated fields In Parent (EditListing.js)
In Child (ItemInfo.js)
I posted a more detailed description in Stackoverflow.... And here is my complete implementation... Parent (EditListing.js)
Child (ItemInfo.js)
Hope this helps |
Not sure if there's any documentation to this, but I've found naming forms with square brackets help to separate multiple forms: {[0,1,2,3].map(i => (
<FormComponent form={`namedForm[${i}]`} key={i} />
)} Now |
@willshu2049 did you find some solution for using redux store with redux-form in this scenario? Facing same issue. |
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. |
Imagine you have multiple items on page and all of them are editable. So every item has its own form. Then textual ID in reduxForm('itemEditForm') is not enough.
Is there a solution for this situation?
The text was updated successfully, but these errors were encountered: