File size: 1,313 Bytes
386e947
 
 
 
 
 
 
 
 
 
aba213a
 
 
386e947
 
 
aba213a
 
386e947
aba213a
386e947
aba213a
386e947
aba213a
386e947
aba213a
386e947
 
 
aba213a
386e947
 
 
 
aba213a
386e947
 
 
aba213a
 
 
386e947
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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