reset page elements to empty when changing page in Taipy

51 Views Asked by At

Currently to reset the page variables and elements I use,

def refresh_project_part(state):
    state.name = None
    state.description = None
    state.p_name = None
    state.p_description = None
    state.cad_filepath= None

But this hinders the page response time. and there is a delay every time I navigate between pages. is it possible to refresh the page somehow?

1

There are 1 best solutions below

0
Florian Jacta On BEST ANSWER

They are no easy way to reinitialize certain elements of a Gui after navigating to a page.

I would suggest creating a dictionary with all the fields of your form and to reinitialize it after saving your form.

Markdown syntax:

from taipy.gui import Gui, notify


form = {"Name":"",
        "Email":"",
        "Phone":""}

md = """
<|{form.Name}|input|>

<|{form.Email}|input|>

<|{form.Phone}|input|>

<|Submit|button|on_action=save|>
"""

def save(state):
    notify(state, "success", "Saved!")
    state.form = {key:"" for key in form.keys()} 

Gui(md).run()

Page Builder:

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

form = {"Name":"",
        "Email":"",
        "Phone":""}

def save(state):
    notify(state, "success", "Saved!")
    state.form = {key:"" for key in form.keys()} 

with tgb.Page() as page:
    for key in form:
        tgb.input('{form.'+key+'}', label=key)

    tgb.button("Submit", on_action=save)


Gui(page).run()

GUI Result

Does that solve your issue?