Hi,
I’m using a multiselect that I want to repopulate anytime I click on a radio button. Along with this, I have a text input associated to a CustomJS callback which filters the choices in the multiselect.
Here is the code:
userList = [('a', 'a'), ('b', 'b'), ('c', 'c')]
folderList = [('d', 'd'), ('e', 'e'), ('f', 'f')]
options = userList
s = MultiSelect(options=options, size=4, width=1000)
ti = TextInput(placeholder='Enter reference')
ti.callback = CustomJS(args=dict(x=options, s=s),
code="s.options = x.filter(i => i[0].toLowerCase().includes(cb_obj.value.toLowerCase()));console.log(x);")
def populateDropdown(attr, old, new):
nonlocal options
if new == 0:# Users
options = userList
else: # Folders
options = folderList
s.options = options
usersFoldersChoice = RadioButtonGroup(labels=[“Users”, “Folders”])
usersFoldersChoice.on_change(‘active’, populateDropdown)
The callback populateDropdown works correctly and each time I switch for "Users" of "Folders", the multiselect is correctly modified. However, the CustomJS callback associated to the TextInput ti dos not work so well. The "console.log(x)" always display the same list, which is here "userList", even if populateDropdown changes the nonlocal variable options. To make the log display folderList, I have to put the "ti.callback" assignment in the callback populateDropdown, as if I had to reassign it each time "options" changes.
Anyone could explain such a behaviour?
