Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data nested with nested fields in redux-form?

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}]

like image 997
ShocKwav3_ Avatar asked Mar 15 '18 14:03

ShocKwav3_


People also ask

What is nested field data?

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.

What nested fields?

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 .

How does Redux handle form?

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.


1 Answers

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}}.

like image 181
Igor Alemasow Avatar answered Oct 05 '22 12:10

Igor Alemasow