0
votes

I am using redux-form immutable, I am trying to do simple todo list, I am using FieldArray for todo items,

When form is submitted, I do not get the value of index since it is read only for user and I am rendering using div. how to get the value of index during submission of the form. How should MyCustom component look like.

<TableRow selectable={false} key={index}>
    <TableRowColumn style={styles.item}>
      <Field name={`${todo}.index`} component={MyCustom} val={index + 1} />
    </TableRowColumn>
    <TableRowColumn style={styles.done}>
      <Field name={`${todo}.done`} component={CheckBox} label=""/>
    </TableRowColumn>
    <TableRowColumn style={styles.description}>
      <Field name={`${todo}.description`} component={Text}/>
    </TableRowColumn>
    <TableRowColumn style={styles.duration}>
      <Field name={`${todo}.duration`} component={Duration} type="number" normalize={integer}/>
    </TableRowColumn>
    <TableRowColumn style={styles.delete}>
      {/* <button type="button" title="X"  onClick={() => fields.remove(index)}>X</button> */}
      <IconButton onClick={() => fields.remove(index)}>
        <DeleteIcon/>
      </IconButton>
    </TableRowColumn>
  </TableRow>

MyCustom

  <div>
    <span>{val}</span>
  </div>
1
You're probably not going to get any answers if you don't have a code example. - Matt Watson

1 Answers

0
votes

index is not a field here, it's just a value. So pass it as a prop.

<MyCustom val={index + 1} />