Avaiga / taipy-gui

Graphical User Interface generator for Taipy
Apache License 2.0
60 stars 20 forks source link

BUG- `navbar` control doesn't call on_change method, and docs are misleading about how to define the LOV #585

Closed Dr-Irv closed 1 year ago

Dr-Irv commented 1 year ago

Description If you want to use the navbar control, there are 2 issues:

  1. If you specify an on_change() function, it never gets called.
  2. If you want to navigate to the pages in your application, then the first element of the LOV needs to be preceded with a "/"

How to reproduce A code fragment

from taipy import Gui
from taipy.gui import State

from typing import Any

def navbar_change(s: State, var_name: str, value: Any):
    print("navbar changed")

page1_md = "## Page 1"
page2_md = "## Page 2"
navbar = (
    "<|navbar|lov={[('/page1', 'First Page'), ('/page2', 'Second Page')]}|"
    + "on_change={lambda s,vn, va: navbar_change(s, vn, va)}|"
    ">"
)

if __name__ == "__main__":
    gui = Gui()

    gui.add_pages({"/": navbar, "page1": page1_md, "page2": page2_md})

    gui.run(
        page=navbar,
        async_mode="threading",
        title="Notify Demo",
        debug=True,
        use_reloader=True,
    )

Expected behavior

The on_change function should be called. The docs should say that if you want your page to be called, then the LOV should be preceded with a "/". In my example above, if you use lov={[('page1', 'First Page'), ('page2', 'Second Page')]} then it always opens up the new page in a second window, and the selection isn't correctly reflected in the navbar.

Screenshots N/A

Runtime environment Please specify relevant indications.

FlorianJacta commented 1 year ago

Thank you. I guess the problem on / for the navbar is either just a doc issue or an issue on the visual element.

FredLL-Avaiga commented 1 year ago

I think the leading / has been addressed in the doc on_change is not supported on navbar and the doc should be fixed about it

FredLL-Avaiga commented 1 year ago

Doc change

Dr-Irv commented 1 year ago

As a related issue, it would be nice if navbar could be used to "navigate" to a part with a partial. I'd like to have a navbar at the top of the page that navigates to a page, but then within that page, have a navbar that changes a partial within the page.

If I should open up a separate issue for this, let me know.

FredLL-Avaiga commented 1 year ago

You can create another issue. But Navbar is really dedicated to navigating to pages. I guess we could find another component that does what you need

Dr-Irv commented 1 year ago

You can create another issue. But Navbar is really dedicated to navigating to pages. I guess we could find another component that does what you need

https://github.com/Avaiga/taipy-gui/issues/592