What you’ll learn
- How FormEngine displays errors automatically in your form
- Customizing error messages for better UX
- Handling multiple validation rules on one field
- Reading errors programmatically via callbacks
- Validating untouched fields before submit
- Styling and positioning error messages
- Common mistakes that hide or suppress errors
How errors display automatically
FormEngine renders error messages automatically near the field that failed validation. The key is setting theerrorType property at the form level — this tells FormEngine which component renders errors.
For example, if you’re using RSuite components, set "errorType": "RsErrorMessage". If you’re using Material UI, use "errorType": "MuiErrorWrapper". If you’re using Mantine, use "errorType": "MtErrorWrapper".
Here’s a form with a required email field:
Customizing error messages
Each validation rule can have a custom message. Define it in theargs.message property of the validation:
"required"— field cannot be empty"email"— field must be a valid email format"maxLength"— field has a character limit (limitin args)"minLength"— field must have minimum characters (limitin args)"min"— number field has a minimum value (limitin args)"max"— number field has a maximum value (limitin args)"regex"— field must match a regular expression pattern (patternin args)
message, FormEngine uses a default error text like “Field is required” or “Invalid email format”.
Multiple validations on one field
You can combine multiple validation rules in thevalidations array. FormEngine checks them in order and displays the first failing rule’s error message:
- User enters password “abc” (less than 8 characters)
- Validation checks: required ✅ pass (it’s not empty)
- Validation checks: minLength ❌ fail — shows “Password must be at least 8 characters”
- Validation stops here — user doesn’t see the uppercase letter error yet
- User updates password to “Abcdefgh” (8 chars, has uppercase)
- Validation checks: required ✅ pass, minLength ✅ pass, regex ✅ pass
- No error shown — field is valid
Reading errors programmatically
You can access validation errors in your React component via two methods:Method 1: onFormDataChange callback
TheonFormDataChange callback fires whenever a field changes. It receives an object with { data, errors }:
errors contains: It’s a plain object where keys are field names (the key property from your form JSON) and values are error messages (strings). If a field has no error, it’s not in this object.
Method 2: getValidationResult() on submit
When users click Submit, you might want to validate all fields at once, including ones they haven’t touched yet. UseformData.getValidationResult():
getValidationResult() returns errors for all fields, even ones the user never clicked on — this is useful before submission to ensure the entire form is valid.
Displaying error summaries
If you want to show all errors in one place (like an error alert at the top), combineonFormDataChange with a summary component:
Styling error messages with errorProps
You can pass custom CSS to error messages via theerrorProps property at the form level:
errorProps applies the same style to all error messages in the form. For per-field styling, use component-specific error props or custom error components (see /core/styling).
Common mistakes that break error display
Mistake 1: Missing errorType
If you don’t seterrorType, errors won’t display visually:
errorType at the top level:
Mistake 2: Typo in validation key
If you misspell the validation key, it won’t run:required, email, minLength, maxLength, min, max, regex.
Mistake 3: Not awaiting getValidationResult()
getValidationResult() is async — you must await it:
Mistake 4: Expecting errors on untouched fields
By default, FormEngine validates on field interaction (onBlur, onChange). Untouched fields don’t show errors until the user interacts:getValidationResult() which forces validation on all fields.
Next steps
- Learn more error handling and custom error components: Core Validation Guide
- Submit forms and handle server-side errors: Form Submission
- Add conditional logic to show/hide fields based on validation state: Conditional Fields
- Build dynamic forms from JSON: Building Forms via Code
- Validate with Zod schemas: Zod Validation
Official resources
- Runtime package: @react-form-builder/core on npm
- Source code and examples: FormEngine GitHub repository
- Full API reference: FormEngine Core