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

Select fails to change value on first try. #3014

Closed
natankeddem opened this issue May 4, 2024 · 6 comments
Closed

Select fails to change value on first try. #3014

natankeddem opened this issue May 4, 2024 · 6 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@natankeddem
Copy link
Contributor

Description

I am testing the following code:

from nicegui import ui

def changed(value):
    ui.notification(value)

options = ["default"]
select = ui.select(options, label="Select", value=options, with_input=True, new_value_mode="add", multiple=True, on_change=lambda e: changed(e.value))
select.props("hide-dropdown-icon use-chips popup-content-style='display: none'")
select.tailwind.width("full")

ui.run(show=False, reload=False)

Here is a video of my experience:
google_screen_recording_2024-05-04T02-39_11.781Z.webm

You will note the first entry disappears on submission and I must retype the name and submit it again to get it to change value.

@rodja
Copy link
Member

rodja commented May 4, 2024

Interesting combination @natankeddem. It works if you use value=options[0] instead of value=options. Could be some Quasar issue. Could you try setting up the same scenario in Quasar only and see if it is reproducible?

@natankeddem
Copy link
Contributor Author

I was basically trying to recreate the example on the Quasar site:
https://quasar.dev/vue-components/select#the-new-value-mode-prop

@rodja
Copy link
Member

rodja commented May 4, 2024

@natankeddem the Quasar example does not have a preselection of values...

@falkoschindler falkoschindler added the bug Something isn't working label May 4, 2024
@falkoschindler falkoschindler added this to the 1.4.24 milestone May 4, 2024
@falkoschindler falkoschindler self-assigned this May 4, 2024
@falkoschindler
Copy link
Contributor

Minimum reproduction:

options = ['default']
ui.select(options, value=options, with_input=True, new_value_mode='add', multiple=True).props('use-chips')

Working counterexample:

ui.select(['default'], value=['default'], with_input=True, new_value_mode='add', multiple=True).props('use-chips')

I guess there is a problem with using the same reference for the options and the value. Maybe we can simply copy on of the arguments. I'll look into it.

@falkoschindler
Copy link
Contributor

Actually I'm not sure if we really need to change the implementation by copying arguments. Maybe we should warn or raise instead if both arguments are the same object, because that doesn't make much sense and the expected behavior is not very clear.

@natankeddem
Copy link
Contributor Author

@falkoschindler thank you so much for digging into this so quickly. @rodja and your commitment to this project is exceptional. Your breakdown of the core issue makes sense, the options and value somehow are interacting strangely when they are sharing a list. In my use case I was attempting to restore the value and options from storage at startup. That is why both objects were the same. I don't have an opinion on the best resolution on this issue, I'll defer to yours.

@falkoschindler falkoschindler modified the milestones: 1.4.24, 1.4.25 May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants