Form Configuration
Schema FormX uses the schema configuration object to define the structure, behavior, and layout of a form. This chapter explains the basic concepts and usage of schema configuration.
Form Component Props
Basic Concepts
Schema
Schema is the core of form configuration, consisting of an array of FieldSchema objects. Each FieldSchema defines a form field.
Example:
FieldSchema
FieldSchema is the configuration object for a single form field, containing the following basic properties:
Components
The components mapping is used to register custom form controls. Each component needs to match the field's component property.
Example:
Layout
The layout configuration is used to control the styles and arrangement of the form. You can set CSS class names and inline styles for the form, groups, fields, labels, and controls.
Example:
Complete Example
Form Configuration
Data Management Modes
Schema FormX supports two data management modes:
Uncontrolled Mode (Recommended)
Use defaultData to set initial values, the form manages data state internally:
Characteristics:
- Simple to use, no manual state sync needed
- Suitable for most scenarios
- Use
refto callgetData()/setData()for data operations
Controlled Mode
Use data + onChange to fully control form data:
Characteristics:
- External full control of data flow
- Suitable for integration with external state (e.g., Redux, URL params)
datainonChangecallback is frozen, shallow copy before modifying
Mode Comparison
Note:
dataanddefaultDatacan be used together. When both are provided,datatakes priority, anddefaultDataserves as the baseline forisDirty()comparison. For example, you can set a baseline withdefaultDatain controlled mode to detect whether form data has been modified.
Controlled vs Uncontrolled
Uncontrolled Form - Use defaultData to set initial values, and the form manages data automatically:
Controlled Form - Use data to control the form data:
Form Reference
Get the form instance via ref to call instance methods:
Best Practices
Schema Structure
- Keep the schema simple and clear
- Use type to define field types
- Use props to pass component-specific props
- Use hidden to dynamically control field visibility
Component Design
- Components should support value and onChange props
- Handle null and undefined values
- Support common HTML attributes
- Provide clear placeholder hints
Data Flow
- Prefer uncontrolled mode for simpler usage
- Use controlled mode when needing precise data control
- Use onChange callback to listen for data changes
- Use ref methods to programmatically operate the form
Note on
onChangetiming: TheonChangecallback fires immediately on every field value change (not on blur). Each value change also triggers dependency linkage and field validation synchronously.
Note on
hiddenfields: Settinghidden: trueon a field only hides it visually (display: none). Hidden fields still participate in validation — if a hidden field hasrequired: true, validation errors will still be raised. Use conditionalrequiredor a customvalidatorto skip validation for hidden fields.