I should have both question input and answer input in a <Field/>. Because of that redux-form docs tells me to use <Fields/>.
<Fields names={['question1', 'answer1']}
component={this.renderInputGroupField} />
<Fields names={['question2', 'answer2']}
component={this.renderInputGroupField} />
<Fields names={['question3', 'answer3']}
component={this.renderInputGroupField} />
rendering fields with this
renderInputGroupField(fields){
return(
<div className="form-group d-block">
<div className="form-group input-group">
<select className="form-select" >
<option>Multiple-Choice</option>
<option>Open-Ended</option>
</select>
<input {...fields.question1.input}
type="text"
className="form-input"
placeholder="Type your question..."/>
</div>
<div className="form-group">
<input {...fields.answer1.input}
type="text"
className="form-input"
placeholder="Comma-separated answer choices" />
</div>
</div>
);
}
To make renderInputGroupField work, I should add {...fields.answer1.input} into <input /> as above. Here is the problem. Names that are passed into fields are different and I can't find a way to change ...fields.answer1.input to ...fields.answer2.input dynamically.
I am not sure if I was able to explain it properly. Thanks for your help.