Hi,
I recently stumbled on the restict option of Autocomplete. I desire to utilize this to allow users to add regular expressions to match numerous items at once. After they enter their selection, I desire for the autocomplete object value to be an empty string. If, in a python callback, I set the value of the Autocomplete instance to an empty string, I’ll envoke the callback. To avoid this, I remove the callback, clear the string, then add the call back back again. (is there a better way to do this in general?)
The problem, when I set restrict=False on the auto-complete object and I select a completion (rather than un-restricted text), the callback is called twice even though at the time of clearing the ‘value’ there are no callbacks on the object. This only happens when:
- restrict=False
- my option is in the completion list
Here is a bokeh server example that illustrates this:
from bokeh.plotting import figure, curdoc
from bokeh.layouts import layout
from bokeh.models import AutocompleteInput
def add_cb(obj):
def hello(attr,old,new):
print('hello', attr, old, new)
obj.remove_on_change('value',this_function)
obj.value=''
obj.on_change('value',this_function)
pass
this_function=hello
obj.on_change('value',hello)
completions=['Apple','Pear','Banana','']
a=AutocompleteInput(title='Restricted',completions=completions,restrict=True)
b=AutocompleteInput(title='UnRestricted',completions=completions,restrict=False)
add_cb(a)
add_cb(b)
l=layout([a,b])
curdoc().add_root(l)
If you type “Dog”, for example, in the ‘Unrestricted’ Autocomplete box, the call back is performed once:
hello value Dog
If you type “Apple”, however, in the ‘Unrestricted’ Autocomplete box, the call back is perfomed twice:
hello value Apple
hello value Apple
Typing Apple in the ‘Restricted’ callback works as expected.
Ultimate desire, clear the contents of the autocomplete object without invoking the second call back --which in my cases toggles the selected value off.
Thanks,