What Are Functional Properties?
Functional properties are special component properties that:- ✅ Contain JavaScript function definitions that execute at runtime
- ✅ Receive the current form data as input
- ✅ Return computed values (strings, numbers, objects, arrays, booleans)
- ✅ Are evaluated each time the component renders
- ✅ Enable dynamic data transformation and computation
- Not React Components: Functional properties return data values, not React elements
- Form Data Access: Functions receive the complete form data as a parameter
- Dynamic Execution: Functions run during component rendering
- Flexible Return Types: Can return any JavaScript value except React nodes
- Transforming raw data into display formats
- Calculating derived values from form inputs
- Implementing conditional styling logic
- Formatting dates, numbers, or currency
- Filtering or sorting data arrays
Basic Usage
To define a functional property, use the fn annotation:Live Example
live
The fn Annotation
Function Signature
Thefn annotation accepts two parameters:
fnDescriptionBegin: The beginning of the function definition, including JSDoc comments and function signaturefnDescriptionEnd: The ending of the function definition (defaults to})
Function Definition Format
Your function definition should follow this pattern:Function Execution Context
The form Parameter
When your function executes, it receives one implicit parameter:form. This object contains all form field values keyed by their component
keys. The full context of the function looks like this:
Return Values
Functional properties can return any JavaScript value except React elements:- Strings: For text display, labels, formatted values
- Numbers: For calculations, metrics, scores
- Booleans: For conditional logic, flags, toggles
- Objects: For configuration, styles, complex data
- Arrays: For lists, collections, filtered data
- null/undefined: When no value should be returned
Practical Examples
Important: The following examples show complete function bodies for illustration purposes. In actual usage, these function bodies would be defined in the form JSON configuration, not in the component definition itself. The component only declares the function signature using thefn annotation.
Example 1: Data Formatting and Transformation
Transform raw data into user-friendly formats:Live Example
live
Example 2: Conditional Logic and Business Rules
Implement business logic that changes based on form data:statusTitle
statusMessage
requirements
indicatorStyle
Live Example
live
Form JSON Representation
When you define a component with functional properties, the function bodies are specified in the form JSON. Here’s how functional properties appear in form JSON:- The
fnSourcefield contains the complete JavaScript function body - The function body should return a value
- Access form data using the
formparameter
Summary
Functional properties using thefn annotation provide a powerful way to add dynamic behavior to your form components:
- Dynamic Values: Compute values based on current form data
- Data Transformation: Transform raw data into display-ready formats
- Business Logic: Implement complex rules and calculations
- Flexible Return Types: Return strings, numbers, objects, arrays, or booleans
- Form JSON Integration: Function bodies defined in form configuration
- When you need values that change based on form data
- For data formatting and transformation
- To implement business rules and calculations
- When you need dynamic configuration or styling
- For static values (use regular properties)
- When returning React elements (use component rendering)
- For extremely performance-sensitive operations
- When simple conditional rendering suffices