AutocompleteInput does not reflect changes in the value attribute
See original GitHub issuebokeh --version 1.4.0
python --version Python 3.7.6
Expected: AutocompleteInput reflects any text changes made in the text input box, no matter how they got there. Actual: When changing the value in the textbox, the values reflected in the textbox are the last change made from the completions list.
It might easily be different than what the value property of the widget actually holds. The changes do not trigger the on_change method.
I used the following example, taken from another issue.
from bokeh.models.widgets.inputs import AutocompleteInput
from bokeh.plotting import curdoc
input_box = AutocompleteInput()
input_box.title = "Foo Bar"
input_box.value = "400"
input_box.completions = ["100001", "12344556", "3194567289", "209374209374"]
def update():
print(input_box.value)
input_box.on_change('value', lambda attr, old, new: update())
curdoc().add_root(input_box)
The user inputs 10 and selects 100001. The user tries options starting with 95. There aren’t any. The number 95 remains in the textbox, while the widget’s value remains 100001. The worst part is that if the user decides to re-select 100001, the option of 100001 appears, but upon selecting it, the textbox still shows 95.
The same holds if, for some reason, we would like to allow the user to input other values not in the Autocomplete list of options. The change does not trigger the attribute change, so we can’t use the entered value.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top GitHub Comments
Workaround:
Then anywhere you’d normally use
input.value
, instead useinput.value_input
..value_input
is updated with every new character typed, but not when the user selects from the drop down.fix_value()
fixes this defect, so that.value_input
always contain the latest user entry, no matter how it got there.Regarding a permanent solution, I’d argue that
.value
should keep its current semantics, while.value_input
should change semantics to incorporate what the abovefix_value
function does.Ni! This has been an issue for me. I think it makes sense to update ‘value’ on all cases, be it selecting from the menu or pressing ‘return’. The developer can keep track of changes of same value if they need to ignore those. But the other way around ain’t true. That is, if I need to act on changes of same value I need bokeh to tell me about them.
I’ve bee working around this by setting ‘value’ back to “” at the end of my callbacks (and exiting at the beginning if that is the case). But this causes the entered text to disappear upon selection, which is not very nice for the user.