I am having some concept problem in using FieldArray, I have multiple Select components wired to FieldArray, each select component should update value onChange and should delete it through api. To be able to perform api request I need to access other details for the field like id. I have setup my component something like shown below, it works fine without api call..
renderAdditionalSpeakers({fields}){
return (<div>
{
fields.map((speaker,index)=>
<Field
name={`${speaker}.speakerid`}
label="Choose Speaker"
type="select"
component={this.renderSelectWithDelete}
mandatory='false'
placeholder='Select Speaker'
opts={this.props.speakers}
key={`KEY-${index}`}
deleteaction={() => fields.remove(index)}
onChange={this.onSpeakerChange.bind(this)}
/>
)
}
<div className="form-group row">
<div className="col-sm-3"> </div>
<div className="col-sm-9 col-sm-offset-0">
<Button className="button-theme button-theme-blue" type="button" onClick={() => fields.push({})}>Link More Speaker</Button>
</div>
</div>
</div>);
}
and render method look like this
render() {
var {handleSubmit, invalid, pristine, submitting,speakers,tracks} = this.props;
return(
<div>
<form onSubmit={handleSubmit(this.onFormSubmit.bind(this))}>
<FieldArray name="additionalspeakers" component={this.renderAdditionalSpeakers.bind(this)}/>
</form>
</div>
);
}
From the above code, I need to call api with in ondeleteaction callback and onChange action. This is only possible when I can access the json object which consist of following values
{
"id":"1",
"speakerid":"23",
"sessionid":"102",
"eventid":"200"
}
How to achieve?
Thanks for help.