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}]
Nested field typeedit. The nested type is a specialised version of the object data type that allows arrays of objects to be indexed in a way that they can be queried independently of each other.
When a packed class contains an instance field that is a packed type, the data for that field is packed directly into the containing class. The field is known as a nested field .
Redux Form is very easy to use and implement, we just have to wrap our form component with the HOC provided by Redux Form and we are good to go. Applying validation to the form is very easy in Redux Form, we can apply validation to all the fields as well as validations for individual fields.
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}}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With