Spaces:
Sleeping
Sleeping
import flet as ft | |
from flet import TextField, ElevatedButton | |
from flet_core import ControlEvent | |
import flet_fastapi | |
async def main(page: ft.Page) -> None: | |
page.title = "Some form" | |
dlg = ft.AlertDialog( | |
title=ft.Text("This doesn't work yet!"), on_dismiss=lambda e: print("Dialog dismissed!") | |
) | |
async def open_dlg(e: ControlEvent): | |
page.dialog = dlg | |
dlg.open = True | |
await page.update_async() | |
question: TextField = TextField(label="Question", text_align=ft.TextAlign.LEFT, width=200) | |
answer: TextField = TextField(label="Answer", text_align=ft.TextAlign.LEFT, width=200) | |
button_submit: ElevatedButton = ElevatedButton(text="Send", disabled=True) | |
async def validate(e: ControlEvent) -> None: | |
if all((question.value, answer.value)): | |
button_submit.disabled = False | |
else: | |
button_submit.disabled = True | |
await page.update_async() | |
async def submit(e: ControlEvent) -> None: | |
await open_dlg(e) | |
question.on_change = validate | |
answer.on_change = validate | |
button_submit.on_click = submit | |
await page.add_async( | |
ft.Container(question, alignment=ft.alignment.center) | |
) | |
await page.add_async( | |
ft.Container(answer, alignment=ft.alignment.center) | |
) | |
await page.add_async( | |
ft.Container(button_submit, alignment=ft.alignment.center) | |
) | |
app = flet_fastapi.app(main) # type: ignore |