What Are Valued Components?
Valued components are components that:- ✅ Read data from the form store
- ✅ Write data back to the form store
- ✅ Support two-way data binding
- ✅ Trigger validation automatically
- ✅ Track dirty/touched state
- ✅ Integrate with FormEngine’s reactive system
- Text inputs
- Checkboxes and radio buttons
- Dropdown selects
- Date pickers
- Sliders and range inputs
- Custom interactive widgets
Understanding Data Binding
Data binding is the automatic synchronization between a component’s visual state and the form data store. When a user interacts with a valued component:- User Action → User types in input, checks a box, etc.
- Component Update → Component calls
onChangewith new value - Store Update → FormEngine updates the data store
- Validation → Validation runs (if enabled)
- UI Sync → All components bound to that data key update automatically
Creating Your First Valued Component
Use valued to set the component property that will be displayed in the form data. Only one property of a component can be valued.Example: Custom Rating Component
Let’s create a star rating component that stores a numeric value (1-5) in the form data.Using the Rating Component
Live Example
live
- Component renders with current value from form data (or 0 if not set)
- User clicks on stars →
onChangeis called with new value - FormEngine automatically updates form.data.productRating
- Validation runs if configured
- Component re-renders with new value
Understanding the .valued Property
The.valued modifier is what transforms a regular prop into a data-bound prop:
How .valued Changes Behavior
| Feature | Regular Prop | Valued Prop |
|---|---|---|
| Gets value from | Props | Form data store |
| Updates trigger | Nothing | Form data update |
| Validates | No | Yes |
| Tracks dirty state | No | Yes |
| Available in form data | No | Yes |
Valued Property Types
String Valued Props
Live Example
live
- Component renders with current value from form data (or 0 if not set)
- User clicks on stars →
onChangeis called with new value - FormEngine automatically updates form.data.productRating
- Validation runs if configured
- Component re-renders with new value
Number Valued Props
Live Example
live
Boolean Valued Props
Live Example
live
Array Valued Props
Live Example
live
Advanced Data Binding Patterns
Uncontrolled Valued Props
If thevalued component must have a value other than undefined, then add
an uncontrolledValue, then FormEngine will substitute the
value from uncontrolledValue instead of undefined.
Live Example
live
Validation Integration
Valued components automatically participate in validation:Live Example
live
Real-World Example: Color Picker
Live Example
live
Testing Valued Components
Common Patterns
Pattern 1: Input with Clear Button
Live Example
live
Pattern 2: Toggle Group
Live Example
live
Overriding existing event handlers
Sometimes you need to work with third-party components that have differentonChange event handler signatures. For example, some components
pass the event object as the first parameter instead of the value. FormEngine Core provides a way to handle this through the
overrideEventHandlers function.
When to Use overrideEventHandlers
UseoverrideEventHandlers when:
- A component’s
onChangehandler receives an event object instead of a value - You need to extract the value from a complex event object
- The component uses non-standard event names (e.g.,
onSelectinstead ofonChange) - You need to transform the event data before it reaches the form store
Built-in Event Handlers in FormEngine Core
FormEngine Core currently provides two built-in event handlers:onChange- Triggered when a component’s value changesonBlur- Triggered when a component loses focus
Example: Overriding onChange for Event Object
Below is an example of redefining theonChange and onBlur events for the Input component from the @mui/material library:
Summary
Valued components are essential for creating interactive forms. Key points:- Use
.valuedto enable data binding - Components receive
valueandonChangeprops automatically - FormEngine handles store synchronization
- Validation runs automatically
- Supports all data types (string, number, boolean, array, object)
- Learn about Components with Events to handle user interactions
- Check out Advanced Patterns for complex scenarios