Validation
Validate form inputs with built-in and custom functions.
Built-in Validators
json-render includes common validation functions:
required— Value must be non-emptyemail— Valid email formatminLength— Minimum string length (args:{ "min": N })maxLength— Maximum string length (args:{ "max": N })pattern— Match a regex pattern (args:{ "pattern": "regex" })min— Minimum numeric value (args:{ "min": N })max— Maximum numeric value (args:{ "max": N })numeric— Value must be a numberurl— Valid URL formatmatches— Must equal another field (args:{ "other": { "$state": "/path" } })equalTo— Alias for matches (args:{ "other": { "$state": "/path" } })lessThan— Value must be less than another field (args:{ "other": { "$state": "/path" } })greaterThan— Value must be greater than another field (args:{ "other": { "$state": "/path" } })requiredIf— Required only when another field is truthy (args:{ "field": { "$state": "/path" } })
Using Validation in JSON
Use { "$bindState": "/path" } on the value prop for two-way binding. Validation checks run against the value at the bound path (available as bindings?.value in components):
Validation with Parameters
Custom Validation Functions
Define custom validators in your catalog's functions field. The catalog itself is framework-agnostic — only the schema import varies by platform:
Usage with React
In @json-render/react, use ValidationProvider to supply implementations for your custom validators:
Using in Components
The useFieldValidation and useBoundProp hooks wire validation into your registry components. Validation uses the path from bindings?.value (the bound state path):
See the @json-render/react API reference for full ValidationProvider and useFieldValidation documentation.
Cross-Field Validation
Validation args support { "$state": "/path" } references to compare against other fields. This enables cross-field rules like "confirm password must match password":
Other cross-field examples:
Conditional Validation
Use the enabled field in the validation config to only run checks when a condition is met:
In the component implementation, you can pass enabled to useFieldValidation:
This only validates the company name when the account type is "business".
Validation Timing
Control when validation runs with validateOn:
change— Validate on every input changeblur— Validate when field loses focus (default for Input, Textarea)submit— Validate only on form submission
Form-Level Validation
Use the built-in validateForm action to validate all registered fields at once. This is useful for a "Submit" button that should validate the entire form before proceeding:
The validateForm action runs validateAll() and writes { valid: boolean } to the specified state path (defaults to /formValidation). Your submit handler can then check { "$state": "/formResult/valid" } to decide whether to proceed.
Note: Actions in a list execute sequentially, but
submitFormdoes not automatically gate on validation. Guard submission with a$condvisibility condition on the button or check{ "$state": "/formResult/valid" }inside your action handler to skip submission when the form is invalid.
Next
- Computed Values — derive dynamic prop values
- Watchers — react to state changes
- Generation Modes — how AI generates specs