@@ -126,6 +126,56 @@ class Delivery(BaseModel):
126126 ],
127127 class_name = 'border-top mt-3 pt-1' ,
128128 ),
129+ c .Div (
130+ components = [
131+ c .Heading (text = 'Modal Form / Confirm prompt' , level = 2 ),
132+ c .Markdown (text = 'The button below will open a modal with a form.' ),
133+ c .Button (text = 'Show Modal Form' , on_click = PageEvent (name = 'modal-form' )),
134+ c .Modal (
135+ title = 'Modal Form' ,
136+ body = [
137+ c .Paragraph (text = 'Form inside a modal!' ),
138+ c .Form (
139+ form_fields = [
140+ c .FormFieldInput (name = 'foobar' , title = 'Foobar' , required = True ),
141+ ],
142+ submit_url = '/api/components/modal-form' ,
143+ footer = [],
144+ submit_trigger = PageEvent (name = 'modal-form-submit' ),
145+ ),
146+ ],
147+ footer = [
148+ c .Button (
149+ text = 'Cancel' , named_style = 'secondary' , on_click = PageEvent (name = 'modal-form' , clear = True )
150+ ),
151+ c .Button (text = 'Submit' , on_click = PageEvent (name = 'modal-form-submit' )),
152+ ],
153+ open_trigger = PageEvent (name = 'modal-form' ),
154+ ),
155+ c .Button (text = 'Show Modal Prompt' , on_click = PageEvent (name = 'modal-prompt' ), class_name = '+ ms-2' ),
156+ c .Modal (
157+ title = 'Form Prompt' ,
158+ body = [
159+ c .Paragraph (text = 'Are you sure you want to do whatever?' ),
160+ c .Form (
161+ form_fields = [],
162+ submit_url = '/api/components/modal-prompt' ,
163+ loading = [c .Spinner (text = 'Okay, good luck...' )],
164+ footer = [],
165+ submit_trigger = PageEvent (name = 'modal-form-submit' ),
166+ ),
167+ ],
168+ footer = [
169+ c .Button (
170+ text = 'Cancel' , named_style = 'secondary' , on_click = PageEvent (name = 'modal-prompt' , clear = True )
171+ ),
172+ c .Button (text = 'Submit' , on_click = PageEvent (name = 'modal-form-submit' )),
173+ ],
174+ open_trigger = PageEvent (name = 'modal-prompt' ),
175+ ),
176+ ],
177+ class_name = 'border-top mt-3 pt-1' ,
178+ ),
129179 c .Div (
130180 components = [
131181 c .Heading (text = 'Server Load' , level = 2 ),
@@ -240,3 +290,15 @@ class Delivery(BaseModel):
240290async def modal_view () -> list [AnyComponent ]:
241291 await asyncio .sleep (0.5 )
242292 return [c .Paragraph (text = 'This is some dynamic content. Open devtools to see me being fetched from the server.' )]
293+
294+
295+ @router .post ('/modal-form' , response_model = FastUI , response_model_exclude_none = True )
296+ async def modal_form_submit () -> list [AnyComponent ]:
297+ await asyncio .sleep (0.5 )
298+ return [c .FireEvent (event = PageEvent (name = 'modal-form' , clear = True ))]
299+
300+
301+ @router .post ('/modal-prompt' , response_model = FastUI , response_model_exclude_none = True )
302+ async def modal_prompt_submit () -> list [AnyComponent ]:
303+ await asyncio .sleep (0.5 )
304+ return [c .FireEvent (event = PageEvent (name = 'modal-prompt' , clear = True ))]
0 commit comments