jakezatecky/react-dual-listbox

Is it possible to set the user selection in the selected box programmatically?

Closed this issue · 3 comments

I'm working on a project where we save the results generated by using the dual list box as an xml file, then allow the user to reload it later and edit it. One thing I need to be able to do is programmatically set which item(s) in the Selected box was selected by the user. I can successfully move items into the selected box, but haven't figured out how to make one or more of those items appear selected (blue).
The reason I need to do that is because I have TWO dual listboxes. The user can select one or more items in the first dual listbox, and when one of them is clicked, it sends some other items to the Available box in the second dual listbox.
So when the user re-loads this xml file, I'd like to show items it the first Selected box with one of them highlighted as having been clicked, so it's clear which item in the first dual listbox was selected to populate the second dual listbox.

Is there a way to programmatically do that when loading the data?
I have a class component.

Sorry for the delayed response.

Unfortunately, there is no way to automatically select/highlight an option in the right-hand selection box with this library. You could use the selectedRef of this library with the componentDidMount and componentDidUpdate functions in your class. In that case, you can call the native select object in the DOM and and programmatically select whichever items you please.

Okay, thanks very much for the information, and thanks for making the dual listbox available!

Glad to provide help. Closing this issue as resolved.