7

I have a scenario where there is a list of items and each items have name and value selector side by side(so two inputs). The user selects the name (its radio button) and then selects the value. I am using redux-form and so far what I achieved:

<Field name='item1' component={DropDownPicker} /> <Field name='item2' component={DropDownPicker} />

submitting gives value as {item1: 1, item2: 2}

Now there will lots of values for different category items and the it will be a big messy object with all category data in one place and I want to avoid that.

How can I get this one item data as {first: {item1: 1, item2: 2}} or as a collection [{item1: 1, item2: 2}]

2
  • Did you try to store the data as a list of objects? Commented Mar 15, 2018 at 15:02
  • that might not help me in this case because the input might change Commented Mar 15, 2018 at 15:04

2 Answers 2

13

Wrap items into first object:

<Field name='first.item1' component={DropDownPicker} />
<Field name='first.item2' component={DropDownPicker} />

On submitting you'll get {first: {item1: 1, item2: 2}}.

Sign up to request clarification or add additional context in comments.

1 Comment

generic Field validation does not work in this case const required = value => value ? undefined : 'Required';
0

You can also use FormSection

import { FormSection } from 'redux-form';

then..

<FormSection name="first">
  <Field name="item1" component={DropDownPicker} />
  <Field name="item2" component={DropDownPicker} />
<FormSection>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.