I am trying to select multiple value from from select field, but I can only select one field and I fetch data from API and in API endpoint I can select multiple user like user=1,2,3 and I also want to select multiple user in react js. Here is my code:
This is my form:
<select
multiple={true}
onChange={this.handleChange}
value={this.state.selectedOptions}
className="form-control btn-block"
id="exampleFormControlSelect2 btn-block"
style={{
width: "200px",
color: "rgba(19, 183, 96, 1.0)"
}}
name="idd"
>
{this.state.movies.map(c => (
<option value={c.pk}>{c.user1}</option>
))}
</select>
Here is handle change event and fetch data:
handleChange(event) {
//this.setState({value: event.option});
this.setState({
value: Array.from(event.target.selectedOptions, item => item.value)
});
}
// Get Data From Backend
async componentDidMount() {
try {
const res = await fetch(config.apiUrl.reportModel);
const movies = await res.json();
// console.log(report);
this.setState({
movies
});
} catch (e) {
console.log(e);
}
}
Please help. I'm stuck here and I don't know how to resolve this.