1

I have two functions for getting date from user, which are:

def date_selector():
    with ui.input('Date') as date:
        with date.add_slot('append'):
            ui.icon('edit_calendar').on('click', lambda: menu.open()).classes('cursor-pointer')
    with ui.menu() as menu:
        ui.date().bind_value(date)
    s_date = date.value
    print(s_date)
    return s_date
def tab_date():
    ui.label(date_selector())
    return

But it is not assign value to s_date. How can I make?

Falko
  • 17,076
  • 13
  • 60
  • 105
kur ag
  • 591
  • 8
  • 19

1 Answers1

1

You're creating a ui.date element and immediately read its value. But the user had no chance to set any value, yet.

Instead you should react on the on_change event, e.g. like this:

def handle_date(event):
    ui.label(event.value)
    menu.close()


with ui.input('Date', on_change=handle_date) as date:
    with date.add_slot('append'):
        ui.icon('edit_calendar').on('click', lambda: menu.open()).classes('cursor-pointer')
with ui.menu() as menu:
    ui.date().bind_value(date)
Falko
  • 17,076
  • 13
  • 60
  • 105
  • Answer worked. But I delete the menu.close(), because I use second part as a function and it does not see "menu". Also if I understand correctly, for all evens I should write the event handler. – kur ag May 31 '23 at 11:02