Selection of items from `SelectMultiple` is broken after content update via observe.
See original GitHub issueMy goal is to have two widgets, select
and other
that accept a list of options.
select
may only take on one value, so I chose the RadioButtons
widget for this. other
may take on multiple values, so I used SelectMultiple
. Further, the options available in other
may not contain the value chosen in select.
Ideally (but optionally), the selected items in other
should be cleared when a new item is chosen from select
.
I used widget.observe
to update other
when select
changes, however (here’s the bug) the selection area in the SelectMultiple
does not respond correctly to clicks after updates. For example, when I click one value, another becomes highlighted, or when I select a range an alternate set of values becomes selected. The behavior is erratic and inconsistent, so you might have to try a few times to get it to misbehave.
This code updates the content of other
when the selection of select
is altered:
from ipywidgets import SelectMultiple, RadioButtons, interact
options = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
select_widget = RadioButtons(options=options)
other_widget = SelectMultiple(options=sorted(list(set(select_widget.options).difference(set([select_widget.value])))),
selected_labels=())
other_widget.selected_labels = ()
def update_other(*args):
other_widget.value = ()
other_widget.selected_labels = ()
other_widget.options = list(set(select_widget.options).difference(set([select_widget.value])))
select_widget.observe(update_other)
def printer(select, other):
print(select, other)
interact(printer, select=select_widget, other=other_widget, __manual = True)
Thank you, Mike
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
I just tried both examples with current master (6.0.0b2 + some commits), and they seem to work fine.
I did notice another bug, which I fixed: #883.
I can verify that it’s working on master. I’m closing. Re-open if you see this in the next release.