Overview
Form rendering in FormEngine Core follows a simple yet powerful pattern:- Define your form structure in JSON.
- Configure a view with UI components.
- Render the form using
FormViewer. - Handle form data and events.
- UI-Agnostic: Works with any React UI library.
- Declarative: Define forms in JSON, not imperative code.
- Reactive: Automatic updates when data changes.
- Extensible: Customize every aspect of form behavior.
Basic Form Rendering
The FormViewer Component
TheFormViewer component is the core of form rendering in FormEngine. It takes a form definition and renders it using the specified UI
components.
Main Properties
| Property | Type | Description | Required |
|---|---|---|---|
view | View | UI component configuration | Yes |
getForm | () => string | Function returning form JSON, stringified | Yes |
actions | CustomActions | Custom action handlers | No |
initialData | FormData | Initial form data | No |
language | string | Language code for localization | No |
Form JSON Structure
Basic Form Definition
Forms are defined as JSON objects with a specific structure:Key Sections
version: Form definition version (currently “1”, optional).errorType: Error display component type.form: Root form structure with components.localization: Translation strings (optional).languages: Supported languages (optional).defaultLanguage: Default language code (optional).
Component Structure
Each component in the form has:key: The unique identifier of the component on the form.dataKey: The key of the component in the form (optional), if not specified, the key field is used.type: The component type.props: The component properties (optional).children: The component children (optional).events: Mapping component events to event handlers (optional).schema: Validators used by the component (optional).css: Component Styles (optional).
View Configuration
What is a View?
A view is a collection of UI components that FormEngine uses to render forms. It maps component types (like “MuiTextField”) to actual React components.Using Pre-Built Views
FormEngine provides pre-built views for popular UI libraries:Creating Custom Views
You can create custom views by combining components:Rendering Modes
Basic Rendering
The simplest way to render a form:live
With Initial Data
Pre-populate form fields with data:live
With Custom Actions
Add interactive behavior to forms:live
Programmatic Form Building
Using the Builder API
Instead of writing JSON manually, you can use the builder API:live
Dynamic Form Generation
Generate forms based on dynamic data:Advanced Rendering Concepts
Conditional Rendering
Show/hide components based on conditions. The example below uses therenderWhen property to conditionally draw a group of components. If
form.data.showGroupSwitch is set to true, then the components are displayed.
live
Computed Properties
Dynamically compute property values. The children property of themuiTypography1 component is calculated on the fly using a JavaScript
function.
live
Multiple Fields with Same Data Key
Demonstrate how multiple form fields can be bound to the same data key, enabling synchronized data updates across multiple components. In this example, two text fields and a typography component share the samedataKey “sharedText”. Changing either text field updates the
shared value, which is reflected in both fields and the typography display.
live
- Data Binding: Each component’s
dataKeyproperty links it to a specific key in the form’s data model (sharedTextin this case). - Synchronization: When a user types in either text field, the form engine updates the shared data value, which automatically propagates to all components bound to that key.
- Use Cases: This pattern is useful for creating mirrored inputs, summary displays, or when multiple UI elements need to reflect the same underlying data.
Integration Examples
With React State Management
live
With Routing Libraries
With External APIs
Troubleshooting
Common Issues
- Form Not Rendering
- Make sure that the
getFormfunction returns the correct string JSON. - Verify the view contains all required component types.
- Ensure form JSON has proper structure.
- Components Not Appearing
- Verify component types exist in the view.
- Check for visibility conditions.
- Ensure components have required properties.
- Events Not Firing
- Confirm event names match component prop names.
- Check that actions are properly defined.
- Verify no validation errors are blocking events.
Debugging Tips
Getting Help
If you encounter issues:- Check the documentation for your specific use case.
- Review form JSON for syntax errors.
- Test with minimal example to isolate the issue.
- Consult the community on GitHub discussions.
- File an issue with reproducible example.
For more information:
- Form JSON structure
- Handling form data
- Validation
- Actions and events
- Conditional rendering
- Styling components and forms
Next steps
- Form JSON — Understand the complete JSON schema structure for defining forms
- Validation — Add validation rules to ensure data quality