- How modal windows work with the
Modalcomponent andmodalTypeconfiguration - How to open and close modals using
openModalandcloseModalactions - How to pass data between the main form and modal windows
- How to use built-in modal components and create custom ones
- Practical examples for common modal use cases
How modal windows work
Modal windows in FormEngine Core are built on top of embedded forms. A modal displays a nested form inside a dialog overlay, with the following architecture:- Modal component: The
Modalcomponent serves as a placeholder in your form definition - Modal type: The
modalTypesetting specifies which UI component renders the actual dialog (e.g.,RsModal,MuiDialog) - Modal properties: The
modalfield in the component’s JSON defines properties for the dialog component - Nested form: The modal displays a form template loaded via the
getFormcallback
Configuring modal windows
Setting the modal type
The modalType property in your form JSON specifies which component library should render modal dialogs. This is typically set at the root level of your form definition:Form with modal type configuration
- “MuiDialog” for Material UI components
- “RsModal” for React Suite components
- Your custom modal component type
Defining a modal component
Use theModal component type to create a modal placeholder in your form. The modalTemplate property specifies which form template to
load inside the modal:
Modal component definition
Modal component properties
Themodal field defines properties for the actual dialog component (specified by modalType). These properties vary depending on your
component library:
showLineNumbers
Opening and closing modals
The openModal action
Use theopenModal action to display a modal window. This action accepts several parameters:
openModal parameters
| Parameter | Type | Description |
|---|---|---|
modalKey | string | Required. The key of the Modal component to open. |
useFormData | boolean | If true, passes the current form data to the modal as initial data. |
beforeShow | function | Optional function executed before the modal opens. Return false to cancel opening, or return an object to pass as initial data. |
beforeHide | function | Optional function executed before the modal closes. Return value is passed to the main form when modal closes. |
The closeModal action
Use thecloseModal action to programmatically close the currently open modal:
result parameter is optional and can be any value that will be available to the beforeHide function and main form after closure.
Data flow between forms and modals
Passing data to modals
You can pass initial data to a modal in two ways:- Using
useFormData: true: Passes the entire form data to the modal - Using
beforeShowfunction: Allows selective data passing or transformation
Passing form data to modal
Selective data passing
Receiving data from modals
When a modal closes, data can be returned to the main form through:beforeHidefunction: Processes data before returning to main form- Modal close with result: The
closeModalaction’sresultparameter
Processing modal results
Live examples
Simple confirmation dialog
A basic modal that asks for user confirmation:live
Data editing modal
A modal that allows editing form data with two-way data transfer:live
Conditional modal with validation
A modal that only opens when certain conditions are met, with form validation:live
Custom modal components
FormEngine Core allows you to use custom modal components from your component library.Best practices
1. Keep modal forms focused
- Design modal forms to perform a single, focused task
- Limit the number of fields in modal forms
- Use clear, action-oriented titles (e.g., “Edit Profile”, “Confirm Delete”)
2. Handle modal state properly
- Always provide a way to close the modal (close button, backdrop click, Escape key)
- Consider disabling the main form while modal is open (backdrop helps with this)
- Clear modal data when closed to avoid stale data on next open
3. Use appropriate modal sizes
sm(small): Simple confirmations, alertsmd(medium): Forms with a few fieldslg(large): Complex forms, data tables, detailed informationfull(fullscreen): Maximum content, complex workflows
4. Implement proper data flow
- Use
beforeShowto validate conditions before opening - Use
beforeHideto process and validate data before closing - Return meaningful results from modals to main forms
- Consider using
useFormData: truefor simple data passing
5. Accessibility considerations
- Ensure modals are properly announced to screen readers
- Trap focus within the modal when open
- Provide clear close mechanisms
- Support keyboard navigation (Escape to close, Tab to navigate)
Troubleshooting
Modal doesn’t open
- Check
modalKey: Ensure themodalKeyinopenModalaction matches the Modal component’s key - Verify
modalType: ConfirmmodalTypeis set in form JSON and matches a registered component with ‘modal’ role - Check
beforeShow: IfbeforeShowreturnsfalse, the modal won’t open
Modal data not passing correctly
useFormDatascope:useFormData: truepasses the entire form data objectbeforeShowreturn value: Data returned frombeforeShowoverridesuseFormData- Data structure: Ensure returned data matches the nested form’s expected structure
Modal doesn’t close
closeModalaction: VerifycloseModalaction is properly bound to a button or event- Modal context: Ensure modal has access to the close function through context
- Event handlers: Check for errors in event handlers that might prevent execution
Multiple modals interference
- Unique keys: Each Modal component must have a unique key
- Sequential opening: Avoid opening multiple modals simultaneously unless designed for it
Summary
- Modal windows display nested forms in overlay dialogs using the
Modalcomponent - The
modalTypesetting determines which UI component renders the dialog - Use
openModalandcloseModalactions to control modal visibility - Pass data between forms and modals using
useFormData,beforeShow, andbeforeHide - Follow best practices for modal design, accessibility, and data flow
For more information:
- Embedded forms - Learn about nested forms that power modals
- Actions and events - Detailed guide on action system
- Form JSON structure - Complete form definition reference
- Custom components - Guide to creating custom components
Next steps
- Embedded Forms — Create reusable nested form sections
- Actions & Events — Control modal behavior with custom actions