- I have 4 select dropdowns.
- Selected values should not appear on the rest of the dropdowns list
My state looks like this
this.state = {
selectedDropdownArray: {},
dropdownArray: ['select','1','2','3','4','5']
}
below is my select dropdown component
<SelectDropdown
options={this.state.dropdownArray}
value={this.getValue()}
onChange={this.handleChange.bind(this)}
On handleChange function i am just pushing the value to an object needed for rest of the work first then i am modifying the dropdownArray . The Array List of dropdown should filter based on the selection.
Below is my handleChange function which the dropdown values are filtered.
handleChange(name, value){
switch(name){
case '1' :
this.state.selectedDropdownArray["0"] = value === "select" ? null : value
break;
case '2' :
this.state.selectedDropdownArray["1"] = value === "select" ? null : value
break;
case '3'
...
...
}
let filter = Object.values(this.state.selectedDropdownArray);
let difference = this.state.dropdownArray.filter(x => !filter.includes(x));
}
If 1st dropdown with value 1 is selected, the difference has now the filtered array [2,3,4,5] which i can setState to dropdownArray.
But the 1st dropdown list does not have 1 to display in this select, since the array is already filtered.
What is the valid approach to achieve this problem to have unique selection for each 4 select dropdowns.