How to reset selected values in "multiselect-react-dropdown"

Viewed 1228

How we can reset selected values, like if I want to change selected values.

<Multiselect
                  options={this.state.robotTrackers}
                  onSelect={this.onSessionSelectRemove.bind(this)}
                  onRemove={this.onSessionSelectRemove.bind(this)}
                  displayValue="name"
                  closeOnSelect={true}
                  id="selectTracker"
                  ref={this.multiselectRefTracker}
                  placeholder="Select advertiser's tracker"
                  selectionLimit={5}
                  style={multiselectCustomStyle}
                />

I am trying this but it only clear all selected values not update.

this.multiselectRefTracker.current.resetSelectedValues(['1'])

2 Answers

I'm so sorry I found Multiselect before discovering MultiSelect, not only is its update mechanism non-standard for React (using createRef instead of setting the element's value) but I found it impossible to get resetSelectedValues to work, period.

I know it's not technically an answer to your question, but for anyone else stuck with this I would recommend migrating to MultiSelect instead.

You are on the right path.

Use this.this.multiselectRefTracker.current.resetSelectedValues() instead of this.multiselectRefTracker.current.resetSelectedValues(['1'])

I hope this would help you.

Related