redux-form initialize FieldArray

133 Views Asked by At

I'm trying to create a redux form which integrates many aspects of redux-form. To give a better introduction to the project I would like to share the main goals with you. At the moment i've a dynamic form which can be extended with participants. Each participant has a superior. On user input (Async.Creatable React select) I request (call to API) all users based on the text. To sum up, an Autosuggestion. When receiving the users I make a second call to get the corresponding superior. Afterwards I would like to autofill the fields for the participant as well as for the superior. Everything works quite well for the first participant + superior. Unlike the first participant the second superior is not getting autofilled. Is it required to call the initialize action (redux-form) manual, when mutating the initalValues Property? The function getFormData access the current state. These state is as expected and contains the following data. These state is created with the LOAD action of redux-form

initial : attendees : Array(2) <-- Autofilled fields [{name: FirstTest, firstName: FirstTest}, {name: SecondTest, firstName: SecondTest}]

const mapStateToProps = (state) => {
  const attendeesFromFormData = getFormData(state, REGISTRATION_FORM, [{}]).attendees
  const attendees = attendeesFromFormData ? attendeesFromFormData : [{}]
  return {
    initialValues: {
      attendees: attendees
    }
  }
}

export default connect(mapStateToProps, {searchADUser, autoFillAttendee, getADUser})(reduxForm({
  form: REGISTRATION_FORM,
  enableReinitialize: true
})(RegistrationForm))
1

There are 1 best solutions below

0
On

Okay after a bit research and testing I find a simple solution for my problem. Each time you add a participant you have to initialize manually the redux-form.