question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AutocompleteInput does not reflect changes in the value attribute

See original GitHub issue

bokeh --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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
redhogcommented, Oct 29, 2020

Workaround:

input = bokeh.models.AutocompleteInput(
    completions="100001", "12344556", "3194567289", "209374209374"],
    value="100001", title='test')
def fix_value(attr, old, new):
    input.value_input = input.value
input.on_change("value", fix_value)

Then anywhere you’d normally use input.value, instead use input.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 above fix_value function does.

0reactions
solstagcommented, Nov 29, 2021

After some more testing, the only case where the value of the input field is not correctly updated, is if the same completion value is selected twice in a row:

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MetroUI: Cannot change data-autocomplete attribute in ...
I found a workaround by using m4q 's insertAfter method. So I just made an anchor tag with an id, and insert my...
Read more >
HTML attribute: autocomplete - MDN Web Docs
The HTML autocomplete attribute lets web developers specify what if any permission the user agent has to provide automated assistance in ...
Read more >
AutoCompleteInput - Component Kitchen
AutoCompleteInput doesn't give the user a way of seeing the complete set of ... booleanAttributeValue(name, value) static method ... render(changed) method.
Read more >
Input Components - React-admin - Marmelab
Value of the input if the record has no value for the source . ... If true , the input is disabled and...
Read more >
Place Autocomplete | Maps JavaScript API - Google Developers
Note: AutocompleteService does not add any UI controls. Instead, the above methods ... Call setOptions() to change an option's value for an existing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found