Spaces:
Running
Running
import flet as ft | |
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!") | |
) | |
await page.add_async(dlg) | |
async def open_dlg(e: ft.ControlEvent) -> None: | |
dlg.open = True | |
await page.update_async() | |
question = ft.TextField(label="Question", text_align=ft.TextAlign.LEFT, width=200) | |
answer = ft.TextField(label="Answer", text_align=ft.TextAlign.LEFT, width=200) | |
submit_button = ft.ElevatedButton(text="Send", disabled=True) | |
async def validate(e: ft.ControlEvent) -> None: | |
if all((question.value, answer.value)): | |
submit_button.disabled = False | |
else: | |
submit_button.disabled = True | |
await page.update_async() | |
async def submit(e: ft.ControlEvent) -> None: | |
await open_dlg(e) | |
question.on_change = validate | |
answer.on_change = validate | |
submit_button.on_click = submit | |
await page.add_async( | |
ft.Container(question, alignment=ft.alignment.center), | |
ft.Container(answer, alignment=ft.alignment.center), | |
ft.Container(submit_button, alignment=ft.alignment.center) | |
) | |
app = flet_fastapi.app(main) # type: ignore |