You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.
I have a page which does something along these lines.
Create the redux store
Display the initial page
Get some input from the user
Get data from a web server
Display a form based on that data
If the returned data is {a: 1, b: 2, c: 3}, I will create a form with three fields, labeled a, b and c. These values are stored in the model at foo.bar.a, foo.bar.b, ... If the returned data is {a: 1, b: 2, d: 4, e: 8}, then I create a form with four fields (a,b,d,e). This worked fine when I was using a React Form, since I could set up a default value for each field. react-reduce-form does not, as far as I can tell, support default values, but requires that the value be in the model.
Since I initialize the store before I know what the fields will be, I cannot set them in the initial state. There is not even a finite set of possible values, so I cannot preset all possible values.
if(state.fieldsForFrom){if(state.myForm.values){return<MyFormfields={state.fieldsForForm}/>}else{// Update the state with the default field values, now that we know what the fields are// (Also, the dispatch needs to be done in a promise/future/async wrapper, since the store// cannot be modified while a render is in progressstore.dispatch(createInitValuesAction(state.fieldsForForm));return<span/>;}}else{return<span/>;}
The text was updated successfully, but these errors were encountered:
I'm still trying to understand what exactly you're trying to accomplish. Do you want to asynchronously set initial values for each field? If so, use actions.load(model, value):
somePromise().then((values)=>{// This will set the initial state of foo.bar to the valuesdispatch(actions.load('foo.bar',values));});
This shows what I am trying to do. When you click the Add Fields button, it updates state.data.fields to have additional members. The form then gets a new dropdown for each member. Clicking Show State does a console.log of the current state to see what is happening.
Adding defaultValue to the <Control.select> sets the value correctly. Removing it sets the value to 1. I am not able to get the same error here that I saw in my original code base.
At this point, I know how to do what I want to do, but I think that the documentation does not mention defaultValue.
I have a page which does something along these lines.
If the returned data is
{a: 1, b: 2, c: 3}
, I will create a form with three fields, labeled a, b and c. These values are stored in the model atfoo.bar.a
,foo.bar.b
, ... If the returned data is{a: 1, b: 2, d: 4, e: 8}
, then I create a form with four fields (a,b,d,e). This worked fine when I was using a ReactForm
, since I could set up a default value for each field.react-reduce-form
does not, as far as I can tell, support default values, but requires that the value be in the model.Since I initialize the store before I know what the fields will be, I cannot set them in the initial state. There is not even a finite set of possible values, so I cannot preset all possible values.
My
render
method currently looks something likeDo I instead need to do something like
The text was updated successfully, but these errors were encountered: