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] on_change of selector not working #1422

Closed
1 of 4 tasks
failable opened this issue Jun 18, 2024 · 3 comments
Closed
1 of 4 tasks

[🐛 BUG] on_change of selector not working #1422

failable opened this issue Jun 18, 2024 · 3 comments
Assignees
Labels
💬 Discussion Requires some discussion and decision 🖰 GUI Related to GUI

Comments

@failable
Copy link

failable commented Jun 18, 2024

What went wrong? 🤔

The on_change function of selector is not working.

Expected Behavior

The on_change function of selector should work.

Steps to Reproduce Issue

Test code:

import taipy.gui.builder as tgb
from taipy.gui import Gui


def on_change(state, var, val):
    print(state)
    print(var)
    print(val)


if __name__ == "__main__":
    collection_names = ["collection1", "collection2", "collection3"]
    with tgb.Page() as page:
        tgb.selector(
            label="Collection",
            lov=";".join(collection_names),
            dropdown=True,
            on_change=on_change,
        )

    Gui(page=page).run(
        dark_mode=False,
        debug=True,
        use_reloader=True,
        port=5001,
    )

Solution Proposed

No response

Screenshots

No response

Runtime Environment

macOS 14.5 (23F79), Chrome Version 125.0.6422.142 (Official Build) (x86_64)

Browsers

Chrome

OS

Mac

Version of Taipy

taipy==3.1.1 taipy-config==3.1.1 taipy-core==3.1.1 taipy-gui==3.1.2 taipy-rest==3.1.1 taipy-templates==3.1.1

Additional Context

No response

Acceptance Criteria

  • Ensure new code is unit tested, and check code coverage is at least 90%.
  • Create related issue in taipy-doc for documentation and Release Notes.

Code of Conduct

  • I have checked the existing issues.
  • I am willing to work on this issue (optional)
@failable failable added the 💥Malfunction Addresses an identified problem. label Jun 18, 2024
@FlorianJacta
Copy link
Member

FlorianJacta commented Jun 18, 2024

Hi, your selector is not bound to any variable. This behavior is normal.

I have bound your selector to a variable called selected_collection. Try this code and tell me if this works:

import taipy.gui.builder as tgb
from taipy.gui import Gui

def on_change(state, var, val):
    print(var)
    print(val)


if __name__ == "__main__":
    collection_names = ["collection1", "collection2", "collection"]
    selected_collection = None
    with tgb.Page() as page:
        tgb.selector(
            value="{selected_collection}",
            label="Collection",
            lov=collection_names,
            dropdown=True,
            on_change=on_change,
        )

    Gui(page=page).run(
        dark_mode=False,
        debug=True,
        use_reloader=True,
        port=5001,
    )

@FlorianJacta FlorianJacta self-assigned this Jun 18, 2024
@FlorianJacta FlorianJacta added 🖰 GUI Related to GUI 💬 Discussion Requires some discussion and decision and removed 💥Malfunction Addresses an identified problem. labels Jun 18, 2024
@failable
Copy link
Author

@FlorianJacta Thanks, that works!

@FlorianJacta
Copy link
Member

Great to hear! You can now access your real-time variable selected_collection in any callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💬 Discussion Requires some discussion and decision 🖰 GUI Related to GUI
Projects
None yet
Development

No branches or pull requests

2 participants