keep focus in input field after change
This commit is contained in:
parent
506abd547b
commit
ff8449f980
1 changed files with 10 additions and 4 deletions
|
@ -267,8 +267,14 @@ def show_part_changer(ui_element: nicegui.ui.element, part: Part) -> None:
|
|||
values = [value for value in values if value]
|
||||
vars(part)[member] = values
|
||||
|
||||
def update_location_element(location_ui_element):
|
||||
"""List location information with input fields."""
|
||||
def update_location_element(location_ui_element, focus: Optional[str]=None):
|
||||
"""List location information with input fields.
|
||||
|
||||
Args:
|
||||
location_ui_element: ui_element which content get replaced
|
||||
focus: the levelname of the schema which input field should have the cursor
|
||||
None if no focus should be set
|
||||
"""
|
||||
location_ui_element.clear()
|
||||
with location_ui_element:
|
||||
location_info = part.location.json
|
||||
|
@ -285,7 +291,7 @@ def show_part_changer(ui_element: nicegui.ui.element, part: Part) -> None:
|
|||
label=level.levelname,
|
||||
value=location_info.get(level.levelname, "")
|
||||
).props(
|
||||
'autogrow dense'
|
||||
'autogrow dense' + (' autofocus' if levelname == focus else '')
|
||||
).on_value_change(
|
||||
lambda event, s=level, ui_ele=location_ui_element: save_location(event, s, ui_ele)
|
||||
)
|
||||
|
@ -308,7 +314,7 @@ def show_part_changer(ui_element: nicegui.ui.element, part: Part) -> None:
|
|||
print("Do not save")
|
||||
else:
|
||||
part.location.set(schema.levelname, value)
|
||||
update_location_element(location_ui_element)
|
||||
update_location_element(location_ui_element, focus=schema.levelname)
|
||||
|
||||
|
||||
print(f"Try to let edit {part.name} with {id(ui_element)}.")
|
||||
|
|
Loading…
Reference in a new issue