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

Possible to extract selected items in a combox? #294

Open
CVisler opened this issue Jan 17, 2024 · 2 comments
Open

Possible to extract selected items in a combox? #294

CVisler opened this issue Jan 17, 2024 · 2 comments

Comments

@CVisler
Copy link

CVisler commented Jan 17, 2024

Been trying to create a Solara component with reacton.ipyvuetify elements. Essentially a Combobox in which I eventually want to be able to select items and dynamically store them in a variable - or store them at the click of a button.

I tried this but got stuck:

import solara as s
import reacton.ipyvuetify as v

items = "item1 item2 item3".split()
chips = s.reactive([items[0]])

@s.component
def Page():

    def on_change(widget, event, data):
        chips.set([???])

    with s.ColumnsResponsive(10, large=[6,6]):
        cb = v.Combobox(
            solo_inverted=True,
            background_color="success",
            solo=True,
            items=items,
            chips=True,
            deletable_chips=True,
            multiple=True,
            autofocus=True,
            prepend_inner_icon="mdi-filter-variant",
            placeholder="Select relevant items",
        )

        btn = v.Btn(children=['CHECK'])
        v.use_event(btn, 'click', on_change)
        s.Markdown(f"Selected: {chips.value}")
@mariobuikhuizen
Copy link
Collaborator

This should work:

import solara as s
import reacton.ipyvuetify as v

items = "item1 item2 item3".split()
items_selected = s.reactive([])

chips = s.reactive([items[0]])

@s.component
def Page():

    def on_change(widget, event, data):
        chips.set(items_selected.value)

    with s.ColumnsResponsive(10, large=[6,6]):
        cb = v.Combobox(
            v_model=items_selected.value,
            on_v_model=items_selected.set,
            solo_inverted=True,
            background_color="success",
            solo=True,
            items=items,
            chips=True,
            deletable_chips=True,
            multiple=True,
            autofocus=True,
            prepend_inner_icon="mdi-filter-variant",
            placeholder="Select relevant items",
        )

        btn = v.Btn(children=['CHECK'])
        v.use_event(btn, 'click', on_change)
        s.Markdown(f"Selected: {chips.value}")

@CVisler
Copy link
Author

CVisler commented Jan 29, 2024

Thank you Mario!

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

No branches or pull requests

2 participants