Overview
Custom renderers allow you to create your own UI components for rendering specific parts of your form. JSON Forms uses a tester-based system to determine which renderer should be used for each UI schema element.Tester Functions
A tester is a function that receives a UI schema element and a JSON schema, and returns a number indicating how well the renderer can handle that combination.Tester Type Definition
NOT_APPLICABLE Constant
TheNOT_APPLICABLE constant has a value of -1 and indicates that a tester cannot handle the given combination:
Built-in Tester Functions
JSON Forms provides many built-in tester utilities:Type Checking
Scope Checking
Option Checking
Composing Testers
Creating a Ranked Tester
UserankWith to create a ranked tester from a boolean tester:
Example: Custom Text Control
Here’s a complete example of a custom text control renderer:Example: Custom Control with Options
Create a control that only renders when a specific option is set:Renderer Priority
JSON Forms selects the renderer with the highest rank. Common ranking conventions:- 1: Default renderer
- 2: Slightly specialized renderer
- 3-5: More specialized renderers
- 10+: Highly specialized renderers
Registering Custom Renderers
Register your custom renderer with JSON Forms:Common Built-in Testers
Best Practices
- Use descriptive ranks: Choose ranks that clearly indicate the specificity of your renderer
- Compose testers: Use
and,or, andnotto create complex tester logic - Test thoroughly: Ensure your tester returns the correct rank for all cases
- Document your testers: Clearly document when your custom renderer should be used
- Use type guards: Leverage TypeScript’s type system for better type safety
- Consider the context: Use the
TesterContextto access the root schema and config when needed