0
votes

I am new to Redux Form and I am having some issues figuring out how to set up a specific flow. So I have a form for creating a new user. On this form I have a button that an admin clicks to add the user to a specific organization (the user model is associated with an organizationId - user belongTo organization). When the button is clicked a modal window pops up and allows the user to search through a list of organizations and select a specific organization. After the Admin selects an organization in the modal, I want to display the organization name in a disabled textfield on the original new user form. Heres my dilemma. When the form is submitted, I want to submit the organizations ID, not the name of the organization.

I know that I can achieve this a few different ways, but I was wondering what others thought is the best approach to solving this problem? When an organization is clicked in the modal, should I change the state of selectedOrgId and then on form submission pass that piece of state into my createUser action? Or should I include a hidden input field on the form and set the value equal to this.state.selectedOrgId and then that way the organizationId will be submitted through the forms props?

Is there an easier way to achieve this with Redux Form that I am completely missing?

1
Could you please add your code?Alexandr Lazarev

1 Answers

1
votes

If you don't mind also submitting the organization name, you could have your modal

dispatch(change('userForm', 'organization', { id: 7, name: 'Acme, Inc.' }))

before it closes and then have the disabled input be for "organization.name". You won't need a hidden input for anything because that concept doesn't make sense in Redux Form.

If you have an aversion to deep objects, you could

dispatch(change('userForm', 'organizationId', 7))
dispatch(change('userForm', 'organizationName', 'Acme, Inc.'))