This is a migrated thread and some comments may be shown as answers.

React MultiSelect - how to get selected items

1 Answer 252 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Kara
Top achievements
Rank 1
Kara asked on 16 Nov 2017, 05:52 PM

So all the examples given are for jQuery and show to use the id assigned to the select and use dataItems() to get the selected items in an array. However, for React, I haven't had luck defining a MultiSelect with an id, and I am unsure how to select a specific one to get the selected items. I have several multiselects defined and need to get the selected items that are provided via a remote data source. 

Here is an example of one them: 

<MultiSelect id="materials" dataSource = {this.materialOptions} dataTextField={'material_code'} dataValueField={'material_code'} placeholder='Select Materials...'/>

 

When I view the element it doesn't have the assigned id "materials". So how I can access this outside of the render definition?

1 Answer, 1 is accepted

Sort by
0
Kara
Top achievements
Rank 1
answered on 17 Nov 2017, 07:44 PM
Never mind. I figured it out. For those that may have a similar question what I did was separate my multiselects out into their own files and gave them getSelected() methods and used refs to give them handles that I could then call from the parent file. Worked like a charm. This is a good reference: https://stackoverflow.com/questions/37949981/call-child-method-from-parent
Tags
MultiSelect
Asked by
Kara
Top achievements
Rank 1
Answers by
Kara
Top achievements
Rank 1
Share this question
or