Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Setting options in Select widget doesn't update it's value property #10211

Open
tony-bony opened this issue Jun 21, 2020 · 2 comments
Open

Comments

@tony-bony
Copy link

tony-bony commented Jun 21, 2020

ALL software version info (bokeh, python, notebook, OS, browser, any other relevant packages)

$ bokeh info
Python version      :  3.8.1 (default, Dec 27 2019, 18:06:00) 
IPython version     :  7.12.0
Tornado version     :  6.0.3
Bokeh version       :  2.1.0
BokehJS static path :  /usr/local/lib/python3.8/site-packages/bokeh/server/static
node.js version     :  v13.8.0
npm version         :  6.13.7
OS: Mac OS X Catalina (10.15.5)
Browser: Google Chrome 83.0.4103.106 (Official Build) (64-bit)

Description of expected behaviour and the observed behaviour

The value property should be set automatically when setting the options property and should reflect what widget GUI shows.
Now the value property is not set automatically and must be set manually otherwise there will be inconsistency between what the value is and what GUI show

Complete, minimal, self-contained example code that reproduces the issue

from bokeh.models import Row, CustomJS, Button, Select
from bokeh.plotting import show

select = Select()
button_add = Button(label='Add')  

code_button_add = '''
    select.options = ['option' + select.options.length].concat(select.options)
    console.log(select.value) '''
button_add.js_on_click(CustomJS(args={'select': select}, code = code_button_add))

show(Row(select, button_add))

@bryevdv
Copy link
Member

bryevdv commented Jun 23, 2020

@tony-bony I don't disagree that value should always be in sync with the displayed value. But what should the value change to when new options are set?

  • if the old value is still present in the new options list, presumably just keep it as is.
  • if the old value is removed from the options list, then what?

@tony-bony
Copy link
Author

tony-bony commented Jun 24, 2020

Then the value should be set to the value being displayed by the Bokeh Select widget: that is the first option's value. This is what user sees and this is in my opinion what the model value should be.
With the current callback code when I e.g. start with an empty select and then I set the options then the first option is displayed but the value remains empty.

When I change the callback code to:

code_button_add = '''
    select.options = ['option' + select.options.length].concat(select.options)
    select.value = 'why?'
    console.log(select.value) '''

and using the button I add the first option then the Select widget will display an empty selection (without generating an error) so decision was made in Bokeh to accept the non-existing value (why?) and to display an empty selection.
But each next button click makes the Select widget to display the recently added option however the value of Select widget still remains the same: why? even if it doesn't exist in options. Why? I can't find a logical explanation for doing it this way...?

I think it's OK for the widget to display an empty selection when a wrong value was used that doesn't exist in options, but the value should not be accepted and a warning should be generated in JS console or in Python. On the other hand if an option is displayed it should always correspond to the the internal value.

So if the options are set and the first option is displayed then the internal value should be in sync with it. If the value must remain empty than also the Select widget should show an empty selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants