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

Dropdown value clearing #1574

Closed
ShehanIshanka opened this issue Aug 5, 2022 · 1 comment · Fixed by #1621
Closed

Dropdown value clearing #1574

ShehanIshanka opened this issue Aug 5, 2022 · 1 comment · Fixed by #1621
Assignees
Labels
bug Bug in code ui Related to UI

Comments

@ShehanIshanka
Copy link

ShehanIshanka commented Aug 5, 2022

Wave SDK Version, OS

0.21.1

Actual behavior

I have two dropdowns and I need to clear the selected value of the second dropdown when the value of the first dropdown changes.

This works fine with form by setting the second dropdown value as None.

from h2o_wave import app, main, Q, ui


@app("/")
async def serve(q: Q) -> None:
    if q.args.dropdown1:
        if q.args.dropdown1 != q.client.dropdown1:
            q.client.dropdown1_changed = True
        else:
            q.client.dropdown1_changed = False
        q.client.dropdown1 = q.args.dropdown1
    if q.args.dropdown2:
        if q.client.dropdown1_changed:
            q.client.dropdown2 = None
        else:
            q.client.dropdown2 = q.args.dropdown2

    q.page["example"] = ui.form_card(
        box="1 1 2 2",
        items=[
            ui.dropdown(
                name="dropdown1",
                label="Dropdown1",
                value=q.client.dropdown1,
                trigger=True,
                choices=[
                    ui.choice(name="1", label="Choice 1"),
                    ui.choice(name="2", label="Choice 2"),
                    ui.choice(name="3", label="Choice 3"),
                ],
            ),
            ui.dropdown(
                name="dropdown2",
                label="Dropdown2",
                value=q.client.dropdown2,
                trigger=True,
                choices=[
                    ui.choice(name="a", label="Choice a"),
                    ui.choice(name="b", label="Choice b"),
                    ui.choice(name="c", label="Choice c"),
                ],
            ),
        ],
    )

    await q.page.save()
Screen.Recording.2022-08-05.at.20.59.53.mov

When the dropdowns are in a side panel, you need to set the value of the second dropdown as a value except None.

Scenario 1: Value as None - Not working.

from h2o_wave import app, main, Q, ui

@app("/")
async def serve(q: Q) -> None:
    if not q.client.initialized:
        q.page['meta'] = ui.meta_card(box='')
        q.page['example'] = ui.form_card(box='1 1 2 1', items=[
            ui.button(name='show_side_panel', label='Open side panel', primary=True)
        ])
        q.client.initialized = True
    else:
        if q.args.show_side_panel:
            show_side_panel(q)

        if q.args.dropdown1:
            if q.args.dropdown1 != q.client.dropdown1:
                q.client.dropdown2 = None
            q.client.dropdown1 = q.args.dropdown1
            show_side_panel(q)
        if q.args.dropdown2:
            q.client.dropdown2 = q.args.dropdown2
            show_side_panel(q)
        if q.args.cancel:
            q.page['meta'].side_panel = None
            q.client.dropdown1 = None
            q.client.dropdown2 = None

    await q.page.save()


def show_side_panel(q):
    q.page["meta"].side_panel = ui.side_panel(
        title="Side Panel",
        items=[
            ui.dropdown(
                name="dropdown1",
                label="Dropdown1",
                value=q.client.dropdown1,
                trigger=True,
                choices=[
                    ui.choice(name="1", label="Choice 1"),
                    ui.choice(name="2", label="Choice 2"),
                    ui.choice(name="3", label="Choice 3"),
                ],
            ),
            ui.dropdown(
                name="dropdown2",
                label="Dropdown2",
                value=q.client.dropdown2,
                trigger=True,
                choices=[
                    ui.choice(name="a", label="Choice a"),
                    ui.choice(name="b", label="Choice b"),
                    ui.choice(name="c", label="Choice c"),
                ],
            ),
            ui.button(name='cancel', label='Cancel')
        ],
        events=["dismissed"],
        closable=True,
    )
Screen.Recording.2022-08-05.at.21.04.41.mov

Scenario 2: Value as an empty string - working.

from h2o_wave import app, main, Q, ui

@app("/")
async def serve(q: Q) -> None:
    if not q.client.initialized:
        q.page['meta'] = ui.meta_card(box='')
        q.page['example'] = ui.form_card(box='1 1 2 1', items=[
            ui.button(name='show_side_panel', label='Open side panel', primary=True)
        ])
        q.client.initialized = True
    else:
        if q.args.show_side_panel:
            show_side_panel(q)

        if q.args.dropdown1:
            if q.args.dropdown1 != q.client.dropdown1:
                q.client.dropdown2 = ""
            q.client.dropdown1 = q.args.dropdown1
            show_side_panel(q)
        if q.args.dropdown2:
            q.client.dropdown2 = q.args.dropdown2
            show_side_panel(q)
        if q.args.cancel:
            q.page['meta'].side_panel = None
            q.client.dropdown1 = None
            q.client.dropdown2 = None

    await q.page.save()


def show_side_panel(q):
    q.page["meta"].side_panel = ui.side_panel(
        title="Side Panel",
        items=[
            ui.dropdown(
                name="dropdown1",
                label="Dropdown1",
                value=q.client.dropdown1,
                trigger=True,
                choices=[
                    ui.choice(name="1", label="Choice 1"),
                    ui.choice(name="2", label="Choice 2"),
                    ui.choice(name="3", label="Choice 3"),
                ],
            ),
            ui.dropdown(
                name="dropdown2",
                label="Dropdown2",
                value=q.client.dropdown2,
                trigger=True,
                choices=[
                    ui.choice(name="a", label="Choice a"),
                    ui.choice(name="b", label="Choice b"),
                    ui.choice(name="c", label="Choice c"),
                ],
            ),
            ui.button(name='cancel', label='Cancel')
        ],
        events=["dismissed"],
        closable=True,
    )
Screen.Recording.2022-08-05.at.21.06.07.mov

Expected behavior

Expect to clear the value of a dropdown in a side panel, when it is set as None.

@ShehanIshanka ShehanIshanka added the bug Bug in code label Aug 5, 2022
@mturoci mturoci added the ui Related to UI label Aug 8, 2022
@aalencar aalencar self-assigned this Aug 24, 2022
aalencar added a commit that referenced this issue Sep 14, 2022
Also:
* Fix multi dialog dropdown bug where wave args is set as string for one value and for more than one value it's set as array.
* Improve performance of dialog tests.
* Refactor filtered items for multi dialog. It was implicitly mutating "items" when calling its setter.

closes #1574
aalencar added a commit that referenced this issue Sep 14, 2022
Also:
* Fix multi dialog dropdown bug where wave args is set as string for one value and for more than one value it's set as array.
* Improve performance of dialog tests.
* Refactor filtered items for multi dialog. It was implicitly mutating "items" when calling its setter.

closes #1574
@aalencar
Copy link
Contributor

Related to #1154.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in code ui Related to UI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants