Skip to main content
Version: Current (v7.0.0-beta.1)

Custom Templates

This is an advanced feature that lets you customize even more aspects of the form:

Custom FieldCustom TemplateCustom Widget
What it doesOverrides all behaviourOverrides just the layout (not behaviour)Overrides just the input box (not layout, labels, or help, or validation)
UsageGlobal or per-fieldGlobal or per-fieldGlobal or per-field
Global Example<Form fields={{ MyCustomField }} /><Form templates={{ ArrayFieldTemplate: MyArrayTemplate }} /><Form widgets={{ MyCustomWidget }} />
Per-Field Example"ui:field": MyCustomField"ui:ArrayFieldTemplate": MyArrayTemplate"ui:widget":MyCustomWidget
DocumentationCustom FieldsSee documentation belowCustom Widgets

To understand how Fields, Templates, and Widgets work together, consider how a room is built and furnished:

  • 👷 Custom Field (General Contractor / Room Architect): Oversees the entire room. Dictates end-to-end logic and coordinates any sub-fields, as the built-in ObjectField and ArrayField do.
  • 📐 Custom Template (Framing & Layout): The structural scaffolding. Determines where elements sit relative to each other—arranging titles, descriptions, error banners, and the input slot. It doesn't care what the input control looks like.
  • 🎛️ Custom Widget (Fixture / Appliance): The interactive leaf control the user actually touches—the light switch, faucet, text input, toggle, or date picker. It only takes a value and fires change, focus and blur events.

In version 5, all existing templates were consolidated into a new TemplatesType interface that is provided as part of the Registry. They can also be overloaded globally on the Form via the templates prop as well as per-field through the uiSchema. Further, many new templates were added or repurposed from existing widgets and fields in an effort to simplify the effort needed by theme authors to build new and/or maintain current themes. These new templates can also be overridden by individual users to customize the specific needs of their application. A special category of templates, ButtonTemplates, were also added to support the easy replacement of the Submit button on the form, the Add and Remove buttons associated with additionalProperties and patternProperties on objects and elements of arrays, the Move up and Move down buttons used for reordering arrays, and the Copy button that duplicates an array item. Version 6 added the Clear button that empties a text input. This category, unlike the others, can only be overridden globally via the templates prop on Form.

Below is the table that lists all the templates, their props interface, their uiSchema name and from where they originated in the previous version of RJSF:

TemplateProps TypeUiSchema nameOrigin
ArrayFieldTemplateArrayFieldTemplatePropsui:ArrayFieldTemplateFormerly Form.ArrayFieldTemplate or Registry.ArrayFieldTemplate
ArrayFieldDescriptionTemplateArrayFieldDescriptionPropsui:ArrayFieldDescriptionTemplateFormerly part of @rjsf/core ArrayField, refactored as a template, used in all ArrayFieldTemplate implementations
ArrayFieldItemTemplateArrayFieldItemTemplatePropsui:ArrayFieldItemTemplateFormerly an internal class for ArrayFieldTemplates in all themes, refactored as a template in each theme, used in all ArrayFieldTemplate implementations
ArrayFieldItemButtonsTemplateArrayFieldItemButtonsTemplatePropsui:ArrayFieldItemButtonsTemplateFormerly an internal class for ArrayFieldItemTemplates in all themes, refactored as a template in the core, used in all ArrayFieldItemTemplate implementations
ArrayFieldTitleTemplateArrayFieldTitlePropsui:ArrayFieldTitleTemplateFormerly part of @rjsf/core ArrayField, refactored as a template, used in all ArrayFieldTemplate implementations.
BaseInputTemplateWidgetPropsui:BaseInputTemplateFormerly a widget in @rjsf.core moved to templates and newly implemented in each theme to maximize code reuse.
CyclicSchemaExpandTemplateCyclicSchemaExpandPropsui:CyclicSchemaExpandTemplateAdded in RJSF v6 to support circular $ref cycle detection
DescriptionFieldTemplateDescriptionFieldPropsui:DescriptionFieldTemplateFormerly a field in @rjsf.core moved to templates with the Template suffix. Previously implemented in each theme.
ErrorListTemplateErrorListPropsui:ErrorListTemplateFormerly Form.ErrorList moved to templates with the Templates suffix. Previously implemented in each theme.
FallbackFieldTemplateFallbackFieldTemplatePropsui:FallbackFieldTemplateAdded in RJSF v6
FieldErrorTemplateFieldErrorPropsui:FieldErrorTemplateFormerly internal ErrorList component accessible only to SchemaField
FieldHelpTemplateFieldHelpPropsui:FieldHelpTemplateFormerly internal Help component accessible only to SchemaField
FieldTemplateFieldTemplatePropsui:FieldTemplateFormerly Form.FieldTemplate or Registry.FieldTemplate
GridTemplateGridTemplatePropsui:GridTemplateTheme dependent implementations of a Grid element for either rows or columns
MarkdownTemplateMarkdownTemplatePropsui:MarkdownTemplateAdded in RJSF v7 to make markdown rendering opt-in
MultiSchemaFieldTemplateMultiSchemaFieldTemplatePropsui:MultiSchemaFieldTemplateFormerly part of @rjsf/core MultiSchemaField`, refactored as a template
ObjectFieldTemplateObjectFieldTemplatePropsui:ObjectFieldTemplateFormerly Form.ObjectFieldTemplate or Registry.ObjectFieldTemplate
OptionalDataControlsTemplateOptionalDataControlsTemplatePropsui:OptionalDataControlsTemplateNew feature in V6
TitleFieldTemplateTitleFieldPropsui:TitleFieldTemplateFormerly a field in @rjsf.core moved to templates with the Template suffix. Previously implemented in each theme.
UnsupportedFieldTemplateUnsupportedFieldPropsui:UnsupportedFieldTemplateFormerly a field in @rjsf.core moved to templates with the Template suffix.
WrapIfAdditionalTemplateWrapIfAdditionalTemplatePropsui:WrapIfAdditionalTemplateFormerly an internal component in @rjsf.core. Previously implemented in most themes.
ButtonTemplates.AddButtonIconButtonPropsn/aFormerly an internal implementation in each theme
ButtonTemplates.ClearButtonIconButtonPropsn/aAdded in RJSF v6
ButtonTemplates.CopyButtonIconButtonPropsn/aAdded in RJSF v5
ButtonTemplates.MoveDownButtonIconButtonPropsn/aFormerly an internal implementation in each theme
ButtonTemplates.MoveUpButtonIconButtonPropsn/aFormerly an internal implementation in each theme
ButtonTemplates.RemoveButtonIconButtonPropsn/aFormerly an internal implementation in each theme
ButtonTemplates.SubmitButtonSubmitButtonPropsn/aFormerly a field in each theme move to templates.ButtonTemplates

ArrayFieldTemplate​

You can use an ArrayFieldTemplate to customize how your arrays are rendered. This allows you to customize your array, and each element in the array. If you only want to customize how the array's title, description or how the array items are presented, you may want to consider providing your own ArrayFieldDescriptionTemplate, ArrayFieldItemTemplate and/or ArrayFieldTitleTemplate instead. You can also customize arrays by specifying a widget in the relevant ui:widget schema, more details over on Custom Widgets.

import { ArrayFieldTemplateProps, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'array',
items: {
type: 'string',
},
};

function ArrayFieldTemplate(props: ArrayFieldTemplateProps) {
return (
<div>
{props.items}
{props.canAdd && (
<button type='button' onClick={props.onAddClick} disabled={props.disabled || props.readonly}>
Add
</button>
)}
</div>
);
}

render(
<Form schema={schema} validator={validator} templates={{ ArrayFieldTemplate }} />,
document.getElementById('app'),
);

You also can provide your own field template to a uiSchema by specifying a ui:ArrayFieldTemplate property with your Component :

import { UiSchema } from '@rjsf/utils';
import ArrayFieldTemplate from './ArrayFieldTemplate';

const uiSchema: UiSchema = {
'ui:ArrayFieldTemplate': ArrayFieldTemplate,
};

or a string value from the Registry :

import { UiSchema } from '@rjsf/utils';

const uiSchema: UiSchema = {
'ui:ArrayFieldTemplate': 'CustomArrayFieldTemplate',
};

Please see the customArray.tsx sample from the playground for another example.

The following props are passed to each ArrayFieldTemplate:

  • canAdd: A boolean value stating whether the array has room for a new item and its options allow one. It is false for an optional array without data, whose data its optionalDataControl starts, and onAddClick does nothing there. It doesn't cover disabled or readonly, under which onAddClick does nothing, so an add button drawn from it has to be disabled on disabled || readonly too.
  • className: The className string.
  • disabled: A boolean value stating if the array is disabled.
  • id: The id of the field in the hierarchy.
  • items: An array of React nodes representing the items in the array.
  • onAddClick: (event?: SyntheticEvent<HTMLElement>) => void: A function that adds a new item to the end of the array. It does nothing where the array's add button can't act, such as on a disabled array.
  • readonly: A boolean value stating if the array is read-only.
  • required: A boolean value stating if the array's heading carries the required marker: where the array is required, unless a field above rendering the same id draws the marked label, as an anyOf/oneOf field does for its option.
  • hideError: A boolean value stating if the field is hiding its errors.
  • schema: The schema object for this array.
  • uiSchema: The uiSchema object for this array field.
  • title: A string value containing the title for the array.
  • optionalDataControl: The control that adds or removes the data of an optional array, when it has one. titleDrawsOptionalDataControl() says whether to lay it out in the heading drawn for title or with the items, so it isn't dropped with a heading that isn't drawn.
  • presentation: The array's plan: whether its heading and description are this template's to draw, which they aren't when they repeat the field above it, and the id its description renders under. It also carries the array's own errors, presentation.errors.messages, with ui:hideError applied, which this template draws, under presentation.errors.id, only where presentation.errors.by is 'self'; under 'template' the FieldTemplate draws them. getErrorsToDraw() gives the messages this template draws. See resolveFieldPresentation(). getArrayDescription() reads the description this template draws from it, falling back to the ui:description or schema description for a template rendered without one.
  • formData: The formData for this array.
  • errorSchema: The optional validation errors for the array field and the items within it, in the form of an ErrorSchema
  • hasErrors: Whether the array shows its own errors, as ui:hideError leaves them. Beneath an anyOf/oneOf field it can differ from presentation.errors.messages, which are the field above's where that field shows them. An array rendered beside anyOf/oneOf options of its own leaves its errors to the selected option, so it is false there.
  • rawErrors: An array of strings listing the array's own errors, which errorSchema doesn't hold. Unlike the rawErrors a FieldTemplate receives, it carries them whatever hideError says. Deprecated, and kept through v7 for a template rendered without a plan: read getErrorsToDraw() for the messages this template draws itself, presentation.errors.messages, with ui:hideError applied, where presentation.errors.by is 'self', since the FieldTemplate draws them under 'template', and hasErrors for an error state, instead. getErrorsToDraw() falls back to rawErrors with hideError without a plan.
  • registry: The registry object.

Note: Array and object field templates are always rendered inside the FieldTemplate. To fully customize an array field template, you may need to specify both ui:FieldTemplate and ui:ArrayFieldTemplate.

ArrayFieldDescriptionTemplate​

The out-of-the-box version of this template will render the DescriptionFieldTemplate with a generated id, if there is a description otherwise nothing is rendered. If you want different behavior for the rendering of the description of an array field, you can customize this template. If you want a different behavior for the rendering of ALL descriptions in the Form, see DescriptionFieldTemplate

import { ArrayFieldDescriptionProps, RJSFSchema, descriptionId } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'array',
items: {
type: 'string',
},
};

function ArrayFieldDescriptionTemplate(props: ArrayFieldDescriptionProps) {
const { description, id } = props;
return (
<details id={descriptionId(id)}>
<summary>Description</summary>
{description}
</details>
);
}

render(
<Form schema={schema} validator={validator} templates={{ ArrayFieldDescriptionTemplate }} />,
document.getElementById('app'),
);

You also can provide your own field template to a uiSchema by specifying a ui:ArrayFieldDescriptionTemplate property with your Component :

import { UiSchema } from '@rjsf/utils';
import ArrayFieldDescriptionTemplate from './ArrayFieldDescriptionTemplate';

const uiSchema: UiSchema = {
'ui:ArrayFieldDescriptionTemplate': ArrayFieldDescriptionTemplate,
};

or a string value from the Registry :

import { UiSchema } from '@rjsf/utils';

const uiSchema: UiSchema = {
'ui:ArrayFieldDescriptionTemplate': 'CustomArrayFieldDescriptionTemplate',
};

The following props are passed to each ArrayFieldDescriptionTemplate:

  • description: The description of the array field being rendered.
  • id: The id of the field in the hierarchy.
  • presentation: The array's plan, whose description id the description renders under when there is one.
  • schema: The schema object for this array field.
  • uiSchema: The uiSchema object for this array field.
  • registry: The registry object.

ArrayFieldItemTemplate​

The ArrayFieldItemTemplate is used to render the representation of a single item in an array. All of the ArrayFieldTemplate implementations in all themes get this template from the registry in order to render array fields items. Each theme has an implementation of the ArrayFieldItemTemplate to render an array field item in a manner best suited to the theme. If you want to change how an array field item is rendered you can customize this template (for instance to remove the buttons rendered by ArrayFieldItemButtonsTemplate).

import { ArrayFieldItemTemplateProps, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'array',
items: {
type: 'string',
},
};

function ArrayFieldItemTemplate(props: ArrayFieldItemTemplateProps) {
const { children, className } = props;
return <div className={className}>{children}</div>;
}

render(
<Form schema={schema} validator={validator} templates={{ ArrayFieldItemTemplate }} />,
document.getElementById('app'),
);

The following props are passed to each ArrayFieldItemTemplate:

  • children: The html for the item's content.
  • buttonsProps: The props to pass to the ArrayFieldItemButtonsTemplate.
  • className: The className string.
  • disabled: Whether the array item's buttons are disabled, by the array's lock or the item's own. Its inputs can stay enabled, under an item's ui:disabled: false.
  • hasToolbar: A boolean value stating whether the array item has a toolbar.
  • index: A number stating the index the array item occurs in items.
  • totalItems: A number stating the total number items in the array.
  • itemKey: A stable, unique key for the array item.
  • readonly: Whether the array item's buttons are read-only, by the array's lock or the item's own. Its inputs can stay editable, under an item's ui:readonly: false.
  • schema: The schema object for this array item.
  • uiSchema: The uiSchema object for this array item.
  • registry: The registry object.
  • parentUiSchema: The UI schema of the array item's parent array field, used for customization in some themes
  • displayLabel: Whether a label sits above the item's control: one the item's FieldTemplate draws, as the plan SchemaField builds for the item says, which is the displayLabel that template is handed, or one the item's field or widget draws itself where its theme declares it labelPlacement: 'above', as a theme whose widgets draw their own label above the control does. Used to place the item's buttons beside its control rather than beside its label.

ArrayFieldItemButtonsTemplate​

The ArrayFieldItemButtonsTemplate is used to render the representation of the buttons used for copying, moving and deleting an item in an array. All of the ArrayFieldItemTemplate implementations in all themes get this template from the registry in order to render array fields items' buttons. Most themes use the core implementation of this template, since the button rendering is identical across them; @rjsf/daisyui provides its own. If you want to change how an array field item's buttons are rendered you can customize this template (for instance to remove the move up/down and remove buttons).

import { ArrayFieldItemButtonsTemplateProps, buttonId, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'array',
items: {
type: 'string',
},
};

function ArrayFieldItemButtonsTemplate(props: ArrayFieldItemButtonsTemplateProps) {
const { disabled, readonly, hasCopy, id, onCopyItem, registry, uiSchema } = props;
const { CopyButton } = registry.templates.ButtonTemplates;
if (!hasCopy) {
return undefined;
}
return (
<CopyButton
id={buttonId(id, 'copy')}
className='array-item-copy'
disabled={disabled || readonly}
onClick={onCopyItem}
uiSchema={uiSchema}
registry={registry}
/>
);
}

render(
<Form schema={schema} validator={validator} templates={{ ArrayFieldItemButtonsTemplate }} />,
document.getElementById('app'),
);

The following props are passed to each ArrayFieldItemButtonsTemplate:

  • className: The className string.
  • disabled: Whether the array item's buttons are disabled, by the array's lock or the item's own. Its inputs can stay enabled, under an item's ui:disabled: false.
  • canAdd: A boolean value stating whether a new item can be added below this one, which is when onAddItem acts. It is false on a disabled or read-only array.
  • hasCopy: A boolean value stating whether the array item can be copied.
  • hasMoveDown: A boolean value stating whether the array item can be moved down.
  • hasMoveUp: A boolean value stating whether the array item can be moved up.
  • hasRemove: A boolean value stating whether the array item can be removed.
  • id: The id of the field in the hierarchy.
  • index: A number stating the index the array item occurs in items.
  • totalItems: A number stating the total number items in the array.
  • onAddItem: (event?: SyntheticEvent<HTMLElement>) => void: Callback function that adds a new item below this item, or does nothing where its button can't act.
  • onCopyItem: (event?: SyntheticEvent<HTMLElement>) => void: Callback function that copies this item below itself, or does nothing where its button can't act.
  • onRemoveItem: (event?: SyntheticEvent<HTMLElement>) => void: Callback function that removes the item from the list, or does nothing where its button can't act, such as under ui:removable: false or on a disabled array.
  • onMoveUpItem: (event?: SyntheticEvent<HTMLElement>) => void: Callback function that moves the item up one spot in the list, or does nothing where its button can't act.
  • onMoveDownItem: (event?: SyntheticEvent<HTMLElement>) => void: Callback function that moves the item down one spot in the list, or does nothing where its button can't act.
  • readonly: Whether the array item's buttons are read-only, by the array's lock or the item's own. Its inputs can stay editable, under an item's ui:readonly: false.
  • itemButtonProps: Props to spread onto each of the item's buttons, keyed by copy, moveDown, moveUp and remove, with a key only for the buttons the item can show. Set when the array's itemLabel option names the item, to title the buttons after it, such as Remove report.pdf; otherwise undefined. A template that renders its own buttons can spread them too, as in <button {...itemButtonProps?.remove} onClick={onRemoveItem}>.
  • schema: The schema object for this array item.
  • style: The optional style to pass to all of the buttons
  • uiSchema: The uiSchema object for this array item.
  • registry: The registry object.

ArrayFieldTitleTemplate​

The out-of-the-box version of this template will render the TitleFieldTemplate with a generated id, if there is a title otherwise nothing is rendered. If you want a different behavior for the rendering of the title of an array field, you can customize this template. If you want a different behavior for the rendering of ALL titles in the Form, see TitleFieldTemplate

import { ArrayFieldTitleProps, RJSFSchema, titleId } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'array',
items: {
type: 'string',
},
};

function ArrayFieldTitleTemplate(props: ArrayFieldTitleProps) {
const { title, id } = props;
return <h1 id={titleId(id)}>{title}</h1>;
}

render(
<Form schema={schema} validator={validator} templates={{ ArrayFieldTitleTemplate }} />,
document.getElementById('app'),
);

You also can provide your own template to a uiSchema by specifying a ui:ArrayFieldTitleTemplate property with your Component :

import { UiSchema } from '@rjsf/utils';
import ArrayFieldTitleTemplate from './ArrayFieldTitleTemplate';

const uiSchema: UiSchema = {
'ui:ArrayFieldTitleTemplate': ArrayFieldTitleTemplate,
};

or a string value from the Registry :

import { UiSchema } from '@rjsf/utils';

const uiSchema: UiSchema = {
'ui:ArrayFieldTitleTemplate': 'CustomArrayFieldTitleTemplate',
};

The following props are passed to each ArrayFieldTitleTemplate:

  • title: The title of the array field being rendered.
  • id: The id of the field in the hierarchy.
  • schema: The schema object for this array field.
  • uiSchema: The uiSchema object for this array field.
  • required: A boolean value stating if the field is required
  • registry: The registry object.

BaseInputTemplate​

The BaseInputTemplate is the template to use to render the basic <input> component for a theme. It is used as the template for rendering many of the <input> based widgets that differ by type and callbacks only. For example, the TextWidget implementation in core is simply a wrapper around BaseInputTemplate that it gets from the registry. Additionally, each theme implements its own version of BaseInputTemplate without needing to provide a different implementation of TextWidget.

If you desire a different implementation for the <input> based widgets, you can customize this template. For instance, say you have a CustomTextInput component that you want to integrate:

import { ChangeEvent, FocusEvent } from 'react';
import {
BaseInputTemplateProps,
getBaseInputProps,
getControlAttributes,
hasWidgetErrors,
RJSFSchema,
toInputValue,
} from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

import CustomTextInput from '../CustomTextInput';

const schema: RJSFSchema = {
type: 'string',
title: 'My input',
description: 'input description',
};

function BaseInputTemplate(props: BaseInputTemplateProps) {
const {
schema,
id,
options,
label,
value,
type,
placeholder,
required,
disabled,
readonly,
autofocus,
onChange,
onChangeOverride,
onBlur,
onFocus,
rawErrors,
hideError,
presentation,
uiSchema,
registry,
...rest
} = props;
const onTextChange = ({ target: { value: val } }: ChangeEvent<HTMLInputElement>) => {
// Use the options.emptyValue if it is specified and newVal is also an empty string
onChange(val === '' ? options.emptyValue || '' : val);
};
const onTextBlur = ({ target: { value: val } }: FocusEvent<HTMLInputElement>) => onBlur(id, val);
const onTextFocus = ({ target: { value: val } }: FocusEvent<HTMLInputElement>) => onFocus(id, val);

const { title, ...baseInputProps } = getBaseInputProps(props);
const inputProps = { ...rest, ...baseInputProps };
// The field's plan leaves out the errors `ui:hideError` hides, and `hasWidgetErrors()` reads the `aria-invalid` it
// gives the control, falling back to `rawErrors` with `hideError` for a widget rendered without a plan. The messages
// are drawn here only where the plan has the widget draw them, under the id the control's `aria-describedby` names,
// and by the `FieldTemplate` otherwise. `rawErrors`, `hideError` and `presentation` stay destructured so that
// `...rest` does not spread them onto the input
const hasError = hasWidgetErrors(props);
const ownErrors = presentation?.errors.by === 'self' ? presentation.errors : undefined;

return (
<>
<CustomTextInput
id={id}
label={label}
value={toInputValue(value)}
placeholder={placeholder}
disabled={disabled}
readOnly={readonly}
autoFocus={autofocus}
error={hasError}
onChange={onChangeOverride || onTextChange}
onBlur={onTextBlur}
onFocus={onTextFocus}
title={title}
{...inputProps}
{...getControlAttributes({ id, presentation })}
/>
{ownErrors && (
<ul id={ownErrors.id}>
{ownErrors.messages.map((error) => (
<li key={error}>{error}</li>
))}
</ul>
)}
</>
);
}

render(
<Form schema={schema} validator={validator} templates={{ BaseInputTemplate }} />,
document.getElementById('app'),
);

Wrapping BaseInputTemplate to customize it​

Sometimes you just need to pass some additional properties to the existing BaseInputTemplate. The way to do this varies based upon whether you are using core or some other theme (such as mui):

import { BaseInputTemplateProps } from '@rjsf/utils';
import { BaseInputTemplate } from '@rjsf/core'; // or from a theme: `const { BaseInputTemplate } = Templates` with `import { Templates } from '@rjsf/mui'`

function MyBaseInputTemplate(props: BaseInputTemplateProps) {
const customProps = {};
// get your custom props from where you need to
return <BaseInputTemplate {...props} {...customProps} />;
}

The following props are passed to the BaseInputTemplate:

  • id: The generated id for this widget;
  • schema: The JSONSchema subschema object for this widget;
  • uiSchema: The uiSchema for this widget;
  • value: The current value for this widget;
  • placeholder: The placeholder for the widget, if any;
  • required: The required status of this widget's control. A label the widget draws is marked from templateMarksRequired(), since the selector of a required anyOf/oneOf field marks its label without being required, and the control of its selected option is required beneath an unmarked label;
  • disabled: A boolean value stating if the widget is disabled;
  • hideError: A boolean value stating if the widget is hiding its errors.
  • readonly: A boolean value stating if the widget is read-only;
  • autofocus: A boolean value stating if the widget should autofocus;
  • label: The computed label for this widget, as a string
  • multiple: A boolean value stating if the widget can accept multiple values. ArrayField passes it to the widget of any multi-select, so getBaseInputProps() puts it only on a file input;
  • type: The type of the input, which the widgets rendering a BaseInputTemplate set, such as 'number' or 'date';
  • pattern: A pattern a widget passes for the input, which replaces the one the schema derives. getBaseInputProps() puts it, inputMode and accept over the input props derived from the schema and adds multiple to a file input, and callerInputProps() returns those three on their own. A pattern counts even when it is undefined, which turns the derived one off;
  • inputMode: An inputMode a widget passes for the input, which replaces the one the schema derives, and which callerInputProps() returns the way it returns pattern;
  • accept: The file types a widget passes for the input, which replace ui:options.accept, and which callerInputProps() returns too;
  • onChange: The value change event handler; call it with the new value every time it changes;
  • onChangeOverride: A BaseInputTemplate implements a default onChange handler that it passes to the HTML input component to handle the ChangeEvent. Sometimes a widget may need to handle the ChangeEvent using custom logic. If that is the case, that widget should provide its own handler via this prop;
  • onBlur: The input blur event handler; call it with the widget id and value;
  • onFocus: The input focus event handler; call it with the widget id and value;
  • options: A map of options passed as a prop to the component (see Custom widget options).
  • options.enumOptions: For enum fields, this property contains the list of options for the enum as an array of { label, value } objects. If the enum is defined using the oneOf/anyOf syntax, the entire schema object for each option is appended onto the { schema, label, value } object.
  • rawErrors: An array of strings listing all generated error messages from encountered errors for this widget. It carries them whatever hideError says. Deprecated, and kept through v7 for a widget rendered without a plan: read hasWidgetErrors(), which follows the aria-invalid the plan gives presentation.control, for the widget's error state instead;
  • presentation: The plan of the field the widget renders the value of: the errors it shows, presentation.errors.messages, with ui:hideError applied, whether the widget draws them itself, presentation.errors.by === 'self', and the attributes its control carries, which getControlAttributes() gives it. Undefined for a widget rendered without a SchemaField above it, or by a field that draws its parts itself.
  • registry: The registry object

CyclicSchemaExpandTemplate​

The CyclicSchemaExpandTemplate is the template rendered by CyclicSchemaField when a circular $ref cycle is detected in the schema. RJSF automatically detects when a $ref would recurse indefinitely (e.g. a schema whose property references its own root) and stops rendering at the cycle boundary. At that point CyclicSchemaField renders this template, which shows a warning message and an expand button that the user can click to render one additional level of the recursive structure. Which fields are expanded is the form's state, by field path, so an expansion survives the field unmounting and mounting again and follows the moves the form makes, of array items and of additional properties renamed or removed; CyclicSchemaField renders an expanded field from expandRefCycle(). When the field one level further would render hidden, through ui:widget: 'hidden' or a deprecatedHandling of 'hide', there is nothing to expand to, so CyclicSchemaField renders nothing in place of this template. Only an object's property is collapsed into a cycle, and ObjectField marks such a property hidden for its ObjectFieldTemplate; an array's items are resolved for each item's data, which ends the recursion, so an array row is never a cycle and a hidden one renders as any hidden item does.

Each theme provides its own implementation. You can replace the template globally via the templates prop on Form, or per-field via ui:CyclicSchemaExpandTemplate in the uiSchema.

import { CyclicSchemaExpandProps, expandButtonId, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

// A schema that is self-referencing
const schema: RJSFSchema = {
$schema: 'http://json-schema.org/draft-07/schema#',
type: 'object',
title: 'Node',
properties: {
value: { type: 'string' },
child: { $ref: '#' },
},
};

function CyclicSchemaExpandTemplate<T = unknown>(props: CyclicSchemaExpandProps<T>) {
const { name, id, onExpand } = props;
const buttonId = expandButtonId(id);
return (
<div className='cyclic-expand'>
<span className='warning'>Circular reference detected for field &quot;{name}&quot;</span>
<button id={buttonId} type='button' onClick={() => onExpand(id)}>
Expand
</button>
</div>
);
}

render(
<Form schema={schema} validator={validator} templates={{ CyclicSchemaExpandTemplate }} />,
document.getElementById('app'),
);

You can also provide a per-field template via uiSchema:

import { UiSchema } from '@rjsf/utils';
import CyclicSchemaExpandTemplate from './CyclicSchemaExpandTemplate';

const uiSchema: UiSchema = {
'ui:CyclicSchemaExpandTemplate': CyclicSchemaExpandTemplate,
};

or a string value from the Registry:

import { UiSchema } from '@rjsf/utils';

const uiSchema: UiSchema = {
'ui:CyclicSchemaExpandTemplate': 'CustomCyclicSchemaExpandTemplate',
};

The following props are passed to the CyclicSchemaExpandTemplate as defined by CyclicSchemaExpandProps in @rjsf/utils:

  • name: The unique name of the field at the cycle boundary, usually the property name within its parent object.
  • id: The id of the field in the hierarchy.
  • onExpand: Callback to call when the user wants to render one additional level; receives the field's id string.
  • schema: The schema object for the field at the cycle boundary.
  • uiSchema: The uiSchema object for this field.
  • registry: The registry object.

DescriptionFieldTemplate​

Each theme implements a DescriptionFieldTemplate used to render the description of a field. If you want to customize how descriptions are rendered you can.

import { DescriptionFieldProps, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'string',
title: 'My input',
description: 'input description',
};

function DescriptionFieldTemplate(props: DescriptionFieldProps) {
const { description, id } = props;
return (
<details id={id}>
<summary>Description</summary>
{description}
</details>
);
}

render(
<Form schema={schema} validator={validator} templates={{ DescriptionFieldTemplate }} />,
document.getElementById('app'),
);

The following props are passed to the DescriptionFieldTemplate:

  • description: The description of the field being rendered.
  • id: The id of the field in the hierarchy.
  • hasErrors: Whether the field it describes shows its own errors, as ui:hideError leaves them. Core's template marks itself data-invalid while it is set.
  • schema: The schema object for the field.
  • uiSchema: The uiSchema object for the field.
  • registry: The registry object.

ErrorListTemplate​

The ErrorListTemplate is the template that renders the all the errors associated with the fields in the Form, at the top. Each theme implements a ErrorListTemplate used to render its errors using components for the theme's toolkit. If you want to customize how all the errors are rendered you can.

import { ErrorListProps, RJSFValidationError, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'string',
title: 'My input',
description: 'input description',
};

function ErrorListTemplate(props: ErrorListProps) {
const { errors } = props;
return (
<details id={id}>
<summary>Errors</summary>
<ul>
{errors.map((error: RJSFValidationError, i: number) => {
return (
<li key={i} className='error'>
{error.stack}
</li>
);
})}
</ul>
</details>
);
}

render(
<Form schema={schema} validator={validator} templates={{ ErrorListTemplate }} />,
document.getElementById('app'),
);

The following props are passed to the ErrorListTemplate:

  • schema: The schema that was passed to Form
  • uiSchema: The uiSchema that was passed to Form
  • errors: An array of all errors in this Form.
  • errorSchema: The ErrorSchema constructed by Form

FallbackFieldTemplate​

The FallbackFieldTemplate is the template that renders opt-in fallback UI to control fields of unknown or unhandled types. Usage of this feature is controlled by the useFallbackUiForUnsupportedType Form prop.

import { FallbackFieldTemplateProps, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'unknownType',
title: 'My input',
};

function FallbackFieldTemplate(props: FallbackFieldTemplateProps) {
const { typeSelector, schemaField } = props;
return (
<div className={'row'}>
<div className={'col-xs-4'}>{typeSelector}</div>
<div className={'col-xs-8'}>{schemaField}</div>
</div>
);
}

render(
<Form schema={schema} validator={validator} templates={{ FallbackFieldTemplate }} />,
document.getElementById('app'),
);

The following props are passed to the FallbackFieldTemplate:

  • schema: The schema for the field
  • uiSchema: The uiSchema for the field
  • registry: The Registry object 1

FieldErrorTemplate​

The FieldErrorTemplate is the template that renders all the errors associated a single field. If you want to customize how the errors are rendered you can.

import { FieldErrorProps, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'string',
title: 'My input',
description: 'input description',
};

function FieldErrorTemplate(props: FieldErrorProps) {
const { errors } = props;
return (
<details id={id}>
<summary>Errors</summary>
<ul>
{errors.map((error: string, i: number) => {
return (
<li key={i} className='error'>
{error.stack}
</li>
);
})}
</ul>
</details>
);
}

render(
<Form schema={schema} validator={validator} templates={{ FieldErrorTemplate }} />,
document.getElementById('app'),
);

The following props are passed to the FieldErrorTemplate:

  • schema: The schema for the field
  • uiSchema: The uiSchema for the field
  • id: The id of the field in the hierarchy.
  • errors: An array of all errors for this field
  • errorSchema: The ErrorSchema for this field
  • registry: The Registry object

FieldHelpTemplate​

The FieldHelpTemplate is the template that renders the help associated a single field. If you want to customize how the help is rendered you can.

import { FieldHelpProps, RJSFSchema, helpId } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'string',
title: 'My input',
description: 'input description',
};

function FieldHelpTemplate(props: FieldHelpProps) {
const { help, id, presentation } = props;
return <aside id={presentation?.help.id ?? helpId(id)}>{help}</aside>;
}

render(
<Form schema={schema} validator={validator} templates={{ FieldHelpTemplate }} />,
document.getElementById('app'),
);

The following props are passed to the FieldHelpTemplate:

  • schema: The schema for the field
  • uiSchema: The uiSchema for the field
  • id: The id of the field in the hierarchy.
  • help: The help information to be rendered
  • hasErrors: Whether the field has errors to show
  • registry: The Registry object
  • presentation: The field's plan, whose help id the help renders under when there is one. An anyOf/oneOf option showing help of its own beneath its field's takes optionHelpId(), so it doesn't repeat the field's helpId(id).

FieldTemplate​

To take control over the inner organization of each field (each form row), you can define a field template for your form.

A field template is basically a React stateless component being passed field-related props, allowing you to structure your form row as you like.

To keep an array item's buttons and an additional property's key input level with the field's control, see Lining up a custom FieldTemplate.

import { FieldTemplateProps, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'string',
};

function CustomFieldTemplate(props: FieldTemplateProps) {
const { id, classNames, style, label, help, required, description, errors, children, presentation } = props;
return (
<div className={classNames} style={style}>
<label htmlFor={id}>
<span id={presentation?.label.id}>{label}</span>
{required ? '*' : null}
</label>
{description}
{children}
{errors}
{help}
</div>
);
}

render(
<Form schema={schema} validator={validator} templates={{ FieldTemplate: CustomFieldTemplate }} />,
document.getElementById('app'),
);

You also can provide your own field template to a uiSchema by specifying a ui:FieldTemplate property with your Component :

import { UiSchema } from '@rjsf/utils';
import CustomFieldTemplate from './CustomFieldTemplate';

const uiSchema: UiSchema = {
'ui:FieldTemplate': CustomFieldTemplate,
};

or a string value from the Registry :

import { UiSchema } from '@rjsf/utils';

const uiSchema: UiSchema = {
'ui:FieldTemplate': 'CustomFieldTemplate',
};

If you want to handle the rendering of each element yourself, you can use the props rawHelp, rawDescription and rawErrors. rawErrors holds only the errors the field is displaying, so it is undefined while ui:hideError is in effect; read errorSchema instead to render the withheld errors your own way.

The following props are passed to a custom field template component:

  • fieldPath: The FieldPath string identifying where this field's data lives, such as friends[0].firstName.
  • id: The id of the field in the hierarchy. You can use it to render a label targeting the wrapped widget, as the for that templateLabelFor() gives, which is none where the field's plan names a group of controls through aria-labelledby.
  • classNames: A string containing the base Bootstrap CSS classes, merged with any custom ones defined in your uiSchema.
  • style: The CSSProperties set by the field's ui:style option.
  • label: The computed label for this field, as a string.
  • keyName: The name of this field's property in its parent object, carrying none of the decoration label may have picked up — a ui:title, or the marker a deprecated schema adds. The key of an additionalProperties property is this rather than its label, so renaming one reads and writes the real key.
  • description: A component instance rendering the field description, when the field's plan says the template draws it (this will use any custom DescriptionFieldTemplate defined in the templates passed to the Form). Render it whenever it is present rather than deciding again from displayLabel.
  • rawDescription: The description the template draws, from the schema or a ui:description, or empty where the plan leaves it to the field or its widget.
  • children: The field or widget component instance for this field row.
  • errors: A component instance listing any encountered errors for this field, when the field's plan says the template draws them.
  • rawErrors: An array of strings listing the generated error messages this field is displaying, undefined while ui:hideError is in effect. Deprecated, and kept through v7 for a template rendered without a plan: read presentation.errors.messages, which has ui:hideError applied, and presentation.errors.by for whether this template draws them, instead, or hasErrors for the field's error state.
  • errorSchema: The tree of errors for this field and its children, carrying every error whatever hideError says.
  • help: A component instance rendering any ui:help uiSchema directive defined, when the field's plan says the template draws it.
  • rawHelp: The ui:help uiSchema directive as it was given, a string or a ReactElement, resolved the same way as the help component that renders it, so it is a truthy check for whether the field has any help at all.
  • hidden: A boolean value stating if the field should be hidden.
  • required: A boolean value stating if the field is required. Mark the label you draw from templateMarksRequired(), which follows the field's plan, so a checkbox the schema lets be false isn't marked.
  • readonly: A boolean value stating if the field is read-only.
  • hideError: A boolean value stating if the field is hiding its errors
  • hasErrors: Whether the field shows its own errors, as ui:hideError leaves them, the state its label, description and help take. Beneath an anyOf/oneOf field it can differ from presentation.errors, which are the field above's where it shows them. SchemaField sets it; a custom field that renders a FieldTemplate itself passes it with the errors.
  • disabled: A boolean value stating if the field is disabled.
  • displayLabel: A boolean value stating if the template renders the label: true only where the field's plan says the template draws it, so it is false where the widget draws its own label, and where ui:label: false turns it off. Deprecated, and kept through v7 for a template rendered without a plan: read presentation.label.by === 'template' instead, or templateDrawsLabel(), which falls back to displayLabel without a plan.
  • presentation: The field's plan, built by SchemaField: who draws its label, description, help and errors, under which ids, and the attributes its control carries. See resolveFieldPresentation(). Where the template draws the label, render the label's text, without the required marker, in an element with the id presentation.label.id, as core's FieldLabel does with its labelId. A <label for> names only the control it points at, so a control or a group whose plan gives it aria-labelledby, and the open list of options of @rjsf/daisyui's and @rjsf/shadcn's SelectWidget, are named through that id, and without it they have no name.
  • schema: The schema object for this field.
  • uiSchema: The uiSchema object for this field.
  • onChange: The value change event handler; Can be called with a new value to change the value for this field.
  • formData: The formData for this field.
  • registry: The registry object.

Note: you can only define a single global field template for a form, but you can set individual field templates per property using "ui:FieldTemplate".

GridTemplate​

The GridTemplate is the template that renders a theme dependent Grid for either a row or column. While it declares only a few properties, it takes any other prop too, in order to support passing any of the properties associated with a Grid implementation for any theme. A prop it doesn't declare can't be read from it, so a template that reads one declares it on its own props, as in GridTemplateProps & { gap?: number }. If you want to customize how grids are rendered you can.

import Grid from '@mui/material/Grid';
import type { GridTemplateProps, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';
import classNames from 'classnames';

const schema: RJSFSchema = {
type: 'string',
title: 'My input',
description: 'input description',
};

function GridTemplate(props: GridTemplateProps) {
const { children, column, className, fieldId, span, ...rest } = props;
return (
<Grid
container={!column}
size={column ? span : undefined}
{...rest}
className={classNames(className, 'my-custom-grid-styling')}
>
{children}
</Grid>
);
}

render(<Form schema={schema} validator={validator} templates={{ GridTemplate }} />, document.getElementById('app'));

The following props are passed to the GridTemplate:

  • children: The contents of the grid template
  • column: Optional flag indicating whether the grid element represents a column, necessary for themes which have components for Rows vs Column
  • span: Optional number of twelfths of a row a column spans, which every theme's GridTemplate converts to its own grid
  • className: Optional class names to add to the grid element
  • style: Optional style to apply to the grid element
  • fieldId: For a column, the id of the first field it holds; for a row, or a column holding no field of its own, the id of the field whose layout grid holds it. It's for naming the row or column in a warning; keep it off the element you render

MarkdownTemplate​

The MarkdownTemplate renders field descriptions, ui:help text and the translatable strings that allow markdown. The core default renders them as plain text, so no markdown library is bundled. @rjsf/core/markdown exports a MarkdownTemplate built on markdown-to-jsx with raw HTML parsing disabled; markdown-to-jsx is an optional peer dependency, so install it alongside @rjsf/core when you use this entry point. Register it and enable markdown for descriptions or help independently:

import Form from '@rjsf/core';
import MarkdownTemplate from '@rjsf/core/markdown';
import { RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = { type: 'string', description: '**bolded** text in the description' };

render(
<Form
schema={schema}
validator={validator}
templates={{ MarkdownTemplate }}
uiSchema={{ 'ui:globalOptions': { enableMarkdownInDescription: true, enableMarkdownInHelp: true } }}
/>,
document.getElementById('app'),
);

Like any template it can also be registered in a theme, or swapped per field with the ui:MarkdownTemplate uiSchema directive.

Because the template is the renderer, any markdown behaviour is yours to choose: register your own component to use a different library, or to pass different options to markdown-to-jsx. Raw HTML, which the @rjsf/core/markdown renderer disables, is the common case:

import { Markdown } from 'markdown-to-jsx/react';
import { MarkdownTemplateProps } from '@rjsf/utils';

/** Renders raw HTML embedded in markdown. Only register this when you control the markdown text — HTML from an
* untrusted source can inject scripts and styles into your page.
*/
function UnsafeHtmlMarkdownTemplate({ children }: MarkdownTemplateProps) {
return <Markdown>{children}</Markdown>;
}

The following props are passed to the MarkdownTemplate:

  • children: The markdown text to render.
  • uiSchema: The uiSchema of the field whose text is being rendered, so a renderer can honour per-field ui:options.
  • registry: The registry object.

MultiSchemaFieldTemplate​

Each theme implements a MultiSchemaFieldTemplate used to render the layout of a MultiSchemaField, i.e. a field described by a oneOf or anyOf schema. The template typically renders a Widget used to select the schema to use, as well as a field for the selected schema.

import { MultiSchemaFieldTemplateProps, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'object',
properties: {
myField: {
oneOf: [
{
type: 'string',
title: 'String Field',
description: 'A field that accepts a string',
},
{
type: 'number',
title: 'Number Field',
description: 'A field that accepts a number',
},
],
},
},
};

function MultiSchemaFieldTemplate(props: MultiSchemaFieldTemplateProps) {
const { selector, optionSchemaField } = props;
return (
<div className='my-multi-schema-field-class'>
{selector}
<hr />
{optionSchemaField}
</div>
);
}

render(
<Form schema={schema} validator={validator} templates={{ MultiSchemaFieldTemplate }} />,
document.getElementById('app'),
);

The following props are passed to the MultiSchemaFieldTemplate:

  • id: The id of the field whose option is selected, which the selected option's field shares, and whose own errors the selector is given. It is unset when the template renders FallbackFieldTemplate's type selector, which isn't given them.
  • selector: The rendered Widget used to select a multischema option.
  • optionSchemaField: The rendered SchemaField representing the selected option.
  • schema: The schema object for the field.
  • uiSchema: The uiSchema object for the field.
  • registry: The registry object.

ObjectFieldTemplate​

import { ObjectFieldTemplateProps, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'object',
title: 'Object title',
description: 'Object description',
properties: {
name: {
type: 'string',
},
age: {
type: 'number',
},
},
};

function ObjectFieldTemplate(props: ObjectFieldTemplateProps) {
return (
<div>
{props.title}
{props.description}
{props.properties.map((element) => (
<div className='property-wrapper' key={element.content.key}>
{element.content}
</div>
))}
</div>
);
}

render(
<Form schema={schema} validator={validator} templates={{ ObjectFieldTemplate }} />,
document.getElementById('app'),
);

You also can provide your own field template to a uiSchema by specifying a ui:ObjectFieldTemplate property with your Component :

import { UiSchema } from '@rjsf/utils';
import ObjectFieldTemplate from './ObjectFieldTemplate';

const uiSchema: UiSchema = {
'ui:ObjectFieldTemplate': ObjectFieldTemplate,
};

or a string value from the Registry :

import { UiSchema } from '@rjsf/utils';

const uiSchema: UiSchema = {
'ui:ObjectFieldTemplate': 'ObjectFieldTemplate',
};

Please see the customObject.tsx sample from the playground for a better example.

The following props are passed to each ObjectFieldTemplate as defined by the ObjectFieldTemplateProps in @rjsf/utils:

  • title: A string value containing the title for the object.
  • optionalDataControl: The control that adds or removes the data of an optional object, when it has one. titleDrawsOptionalDataControl() says whether to lay it out in the heading drawn for title or with the properties, so it isn't dropped with a heading that isn't drawn.
  • presentation: The object's plan: whether its heading and description are this template's to draw, which they aren't when they repeat the field above it, and the id its description renders under. It also carries the object's own errors, presentation.errors.messages, with ui:hideError applied, which this template draws, under presentation.errors.id, only where presentation.errors.by is 'self'; under 'template' the FieldTemplate draws them. getErrorsToDraw() gives the messages this template draws. See resolveFieldPresentation().
  • description: A string value containing the description for the object.
  • disabled: A boolean value stating if the object is disabled.
  • properties: An array of object representing the properties in the object. Each of the properties represent a child with properties described below.
  • onAddProperty: () => void: Callback to use in order to add an new additionalProperty to the object field (to be used with additionalProperties and patternProperties)
  • addButtonProps: Props to spread onto the object's AddButton, { title }, which title it after the object's title or name, such as Add Address; undefined when the object has neither, or when translateString gives an empty TranslatableString.AddNamedButton.
  • readonly: A boolean value stating if the object is read-only.
  • required: A boolean value stating if the object's heading carries the required marker: where the object is required, unless a field above rendering the same id draws the marked label, as an anyOf/oneOf field does for its option.
  • hideError: A boolean value stating if the field is hiding its errors.
  • schema: The schema object for this object.
  • uiSchema: The uiSchema object for this object field.
  • id: The id of the field in the hierarchy.
  • errorSchema: The optional validation errors in the form of an ErrorSchema
  • hasErrors: Whether the object shows its own errors, as ui:hideError leaves them. Beneath an anyOf/oneOf field it can differ from presentation.errors.messages, which are the field above's where that field shows them. An object rendered beside anyOf/oneOf options of its own leaves its errors to the selected option, so it is false there.
  • rawErrors: An array of strings listing the object's own errors, which errorSchema doesn't hold. Unlike the rawErrors a FieldTemplate receives, it carries them whatever hideError says. Deprecated, and kept through v7 for a template rendered without a plan: read getErrorsToDraw() for the messages this template draws itself, presentation.errors.messages, with ui:hideError applied, where presentation.errors.by is 'self', since the FieldTemplate draws them under 'template', and hasErrors for an error state, instead. getErrorsToDraw() falls back to rawErrors with hideError without a plan.
  • formData: The form data for the object.
  • registry: The registry object.

The following props are part of each element in properties:

  • content: The html for the property's content. Key anything you wrap it in by content.key rather than name, which an additionalProperties key's rename changes, remounting the field and losing what its widget holds.
  • name: A string representing the property name.
  • disabled: A boolean value stating if the object property is disabled.
  • readonly: A boolean value stating if the property is read-only.
  • hidden: A boolean value stating if the property should be hidden: whether its field renders hidden through ui:widget: 'hidden' or a deprecatedHandling of 'hide', as its FieldTemplate is told. It can change with the data, such as for a property that dependencies or if/then mark deprecated, and a template that renders a hidden property under another parent, or leaves it out, mounts the property's field afresh when it does. It is decided the way the default SchemaField and CyclicSchemaField resolve the property, see Custom SchemaField.
  • renderedAs: A function returning what the property's field renders as: field, the registry key a ui:field or the schema's $id names, if any; widget, the widget it renders, when that is named by a string; and type, the type in its rjsf-field-<type> class name. A field whose anyOf/oneOf option renders its control reports the widget of the option its data matches, and that option's field and type where it names none of its own, as an untyped anyOf does. Only that outer option is read, so an option that is itself an untyped anyOf/oneOf reports nothing of the option it shows. It resolves the property's schema again, so call it only when you need it. Like hidden, it is decided the way the default SchemaField and CyclicSchemaField resolve the property. A custom field that builds properties itself may leave it out, or set it with createSchemaFieldRenderedAs() from @rjsf/core, calling the function that returns with what it hands the property's SchemaField: schema, uiSchema, formData, fieldPath and registry. That function keeps its last result, so one kept per property across renders reuses it while the property is unchanged, where one created in renderedAs resolves the property on every call. @rjsf/antd keys a property with no renderedAs by nothing, so it gets the default column span.

Note: Array and object field templates are always rendered inside the FieldTemplate. To fully customize an object field template, you may need to specify both ui:FieldTemplate and ui:ObjectFieldTemplate.

OptionalDataControlsTemplate​

Each theme implements a OptionalDataControlsTemplate used to render the Optional Data Controls when that feature has been enabled

import { OptionalDataControlsTemplateProps, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
title: 'test',
properties: {
nestedObjectOptional: {
type: 'object',
properties: {
test: {
type: 'string',
},
},
},
nestedArrayOptional: {
type: 'array',
items: {
type: 'string',
},
},
},
};
const uiSchema = {
'ui:globalOptions': {
enableOptionalDataFieldForType: ['object', 'array'],
},
};
const defaultFormStateBehavior = {
// Set the emptyObjectFields to only populate required defaults to highlight the code working
emptyObjectFields: 'populateRequiredDefaults',
};

function OptionalDataControlsTemplate(props: OptionalDataControlsTemplateProps) {
const { id, registry, label, onAddClick, onRemoveClick } = props;
if (onAddClick) {
return (
<button id={id} className='rjsf-add-optional-data' onClick={onAddClick} title={label}>
+
</button>
);
} else if (onRemoveClick) {
return (
<button id={id} className='rjsf-remove-optional-data' onClick={onRemoveClick} title={label}>
-
</button>
);
}
return <em id={id}>{label}</em>;
}

render(
<Form
schema={schema}
validator={validator}
uiSchema={uiSchema}
defaultFormStateBehavior={defaultFormStateBehavior}
templates={{ OptionalDataControlsTemplate }}
/>,
document.getElementById('app'),
);

The following props are passed to each OptionalDataControlsTemplate as defined by the OptionalDataControlsTemplateProps in @rjsf/utils:

  • id: The generated id for this Optional Data Control instance.
  • label: The label to use for the Optional Data Control
  • onAddClick: Optional callback to call when clicking on the Optional Data Control to add data
  • onRemoveClick: Optional callback to call when clicking on the Optional Data Control to remove data
  • schema: The schema object for this object.
  • uiSchema: The uiSchema object for this object field.
  • registry: The registry object.

TitleFieldTemplate​

Each theme implements a TitleFieldTemplate used to render the title of a field. If you want to customize how titles are rendered you can.

import { RJSFSchema, TitleFieldProps } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'string',
title: 'My input',
description: 'input description',
};

function TitleFieldTemplate(props: TitleFieldProps) {
const { id, required, title } = props;
return (
<header>
<span id={id}>{title}</span>
{required && <mark>*</mark>}
</header>
);
}

render(
<Form schema={schema} validator={validator} templates={{ TitleFieldTemplate }} />,
document.getElementById('app'),
);

The following props are passed to each TitleFieldTemplate:

  • id: The id of the title, which an object's anyOf/oneOf option selector is named by through aria-labelledby. Put it on the element holding the title's text alone, so the selector's name leaves out the required marker and the optional data control.
  • title: The title of the field being rendered.
  • schema: The schema object for the field.
  • uiSchema: The uiSchema object for the field.
  • required: A boolean value stating if the field is required
  • registry: The registry object.
  • outsideFieldset: Set where the title heads no <fieldset>, such as a layout grid's header, so a template that renders a <legend> renders an element valid there instead, as @rjsf/core's renders a <div class="rjsf-title">.

UnsupportedFieldTemplate​

The UnsupportedField component is used to render a field in the schema is one that is not supported by react-jsonschema-form. If you want to customize how an unsupported field is rendered (perhaps for localization purposes) you can.

import { RJSFSchema, UnsupportedFieldProps } from '@rjsf/utils';
import { FormattedMessage } from 'react-intl';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'invalid',
};

function UnsupportedFieldTemplate(props: UnsupportedFieldProps) {
const { schema, reason } = props;
return (
<div>
<FormattedMessage defaultMessage='Unsupported field schema, reason = {reason}' value={{ reason }} />
<pre>{JSON.stringify(schema, null, 2)}</pre>
</div>
);
}

render(
<Form schema={schema} validator={validator} templates={{ UnsupportedFieldTemplate }} />,
document.getElementById('app'),
);

The following props are passed to each UnsupportedFieldTemplate:

  • schema: The schema object for this unsupported field.
  • id: The id of the field in the hierarchy.
  • reason: The reason why the schema field has an unsupported type.
  • registry: The registry object.

WrapIfAdditionalTemplate​

The WrapIfAdditionalTemplate is used by the FieldTemplate to conditionally render additional controls if additionalProperties or patternProperties are present in the schema. You may customize WrapIfAdditionalTemplate if you wish to change the layout or behavior of user-controlled additionalProperties and patternProperties. Core's lays the key, the value and the remove button out on shared grid rows, so the key's input sits level with the value's; see Lining up a custom FieldTemplate.

import {
ADDITIONAL_PROPERTY_FLAG,
additionalKeyId,
hasSchemaMarker,
isAdditionalKeyDisabled,
isAdditionalRemoveDisabled,
RJSFSchema,
WrapIfAdditionalTemplateProps,
} from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'object',
additionalProperties: true,
};

function WrapIfAdditionalTemplate(props: WrapIfAdditionalTemplateProps) {
const {
id,
keyName,
onKeyRenameBlur,
onRemoveProperty,
schema,
children,
uiSchema,
registry,
classNames,
style,
} = props;
const { RemoveButton } = registry.templates.ButtonTemplates;
const additional = hasSchemaMarker(schema, ADDITIONAL_PROPERTY_FLAG);

if (!additional) {
return <div>{children}</div>;
}

return (
<div className={classNames} style={style}>
<label htmlFor={additionalKeyId(id)}>Custom Field Key</label>
<input
className='form-control'
type='text'
id={additionalKeyId(id)}
disabled={isAdditionalKeyDisabled(props)}
onBlur={onKeyRenameBlur}
defaultValue={keyName}
/>
<div>{children}</div>
<RemoveButton
disabled={isAdditionalRemoveDisabled(props)}
onClick={onRemoveProperty}
uiSchema={uiSchema}
registry={registry}
/>
</div>
);
}

render(
<Form schema={schema} validator={validator} templates={{ WrapIfAdditionalTemplate }} />,
document.getElementById('app'),
);

The following props are passed to the WrapIfAdditionalTemplate:

  • children: The children of the component, typically specified by the FieldTemplate.

  • id: The id of the field in the hierarchy. You can use it to render a label targeting the wrapped widget.

  • classNames: A string containing the base Bootstrap CSS classes, merged with any custom ones defined in your uiSchema.

  • style: The CSSProperties set by the field's ui:style option.

  • label: The computed label for this field, as a string.

  • presentation: The field's plan. Whether to label the key input is hasAdditionalKeyLabel(): wherever the value's label is drawn, by the template or the value's own component.

  • hasErrors: Whether the field shows its own errors, as ui:hideError leaves them, which the FieldTemplate hands on from its own hasErrors. Core's WrapIfAdditionalTemplate takes its error class from it alone, so a FieldTemplate that lists the props it forwards one by one includes it.

  • keyName: The name of this field's property in its parent object, carrying none of the decoration label may have picked up — a ui:title, or the marker a deprecated schema adds. The key of an additionalProperties property is this rather than its label, so renaming one reads and writes the real key.

  • required: A boolean value stating if the field is required.

  • readonly: A boolean value stating if the field is read-only.

  • disabled: A boolean value stating if the field is disabled.

  • schema: The schema object for this field.

  • uiSchema: The uiSchema object for this field.

  • onKeyRename: Optional callback used to handle the changing of an additional property key's name with the new value. It is undefined for a field ObjectField doesn't render, such as the root or an array item, as onKeyRenameBlur and onRemoveProperty are, so check for it before calling it

  • onKeyRenameBlur: Optional callback used to handle the changing of an additional property key's name when the input is blurred. The event's target's value will be used as the new value. Its a wrapper callback around onKeyRename. Disable the key input of a disabled or read-only field and of one handed no onKeyRenameBlur, which isAdditionalKeyDisabled() works out

  • onRemoveProperty: Optional callback used to handle the removal of the additionalProperty. Disable the remove button of a disabled or read-only field and of one handed no onRemoveProperty, which isAdditionalRemoveDisabled() works out

  • propertyNamesEnum: The key names this property may be renamed to, derived from the parent schema's propertyNames.enum and narrowed to the names its siblings have not already taken; undefined when the parent schema does not enumerate its property names. Render the key as a dropdown of those names when it is provided, which the AdditionalPropertyKeySelect component from @rjsf/utils does using the theme's own SelectWidget

  • keyNotAllowed: Whether the parent schema forbids this property's key, which its row's errors then say. Mark the key input invalid while it is, which getAdditionalKeyAttributes() from @rjsf/utils does

ButtonTemplates​

There are several buttons that are potentially rendered in the Form. Each of these buttons have been customized in the themes, and can be customized by you as well. All but one of these buttons (i.e. the SubmitButton) are rendered currently as icons with title text for a description.

Each button template (except for the SubmitButton) accepts, as props, the standard HTML button attributes along with the following:

  • iconType: An alternative specification for the type of the icon button.
  • icon: The name representation or actual react element implementation for the icon. @rjsf/core's IconButton draws only plus, copy, arrow-up, arrow-down and remove, and no icon for any other name.
  • uiSchema: The uiSchema object for this field.
  • registry: The registry object.

AddButton​

The AddButton is used to render an add action on a Form for both a new additionalProperties or patternProperties element for an object or a new element in an array. An expandable object's AddButton is passed a title naming the object, such as Add Address; an array's is passed none. You can customize the AddButton to render something other than the icon button that is provided by a theme as follows:

import React from 'react';
import { IconButtonProps, RJSFSchema } from '@rjsf/utils';
import { FormattedMessage } from 'react-intl';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'array',
items: { type: 'string' },
};

function AddButton(props: IconButtonProps) {
const { icon, iconType, registry, uiSchema, ...btnProps } = props;
return (
<button type='button' {...btnProps}>
{icon} <FormattedMessage defaultMessage='Add' />
</button>
);
}

render(
<Form schema={schema} validator={validator} templates={{ ButtonTemplates: { AddButton } }} />,
document.getElementById('app'),
);

ClearButton​

The ClearButton is rendered by BaseInputTemplate to clear a text input's value when the allowClearTextInputs option is enabled. You can customize the ClearButton to render something other than the icon button that is provided by a theme as follows:

import React from 'react';
import { IconButtonProps, RJSFSchema, UiSchema } from '@rjsf/utils';
import { FormattedMessage } from 'react-intl';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'string',
};

const uiSchema: UiSchema = {
'ui:options': { allowClearTextInputs: true },
};

function ClearButton(props: IconButtonProps) {
const { icon, iconType, registry, uiSchema, ...btnProps } = props;
return (
<button type='button' {...btnProps}>
{icon} <FormattedMessage defaultMessage='Clear' />
</button>
);
}

render(
<Form
schema={schema}
uiSchema={uiSchema}
formData='Clear me'
validator={validator}
templates={{ ButtonTemplates: { ClearButton } }}
/>,
document.getElementById('app'),
);

CopyButton​

The CopyButton is rendered by ArrayFieldItemButtonsTemplate to duplicate an array item when the copyable option is enabled (it is off by default). You can customize the CopyButton to render something other than the icon button that is provided by a theme as follows:

import React from 'react';
import { IconButtonProps, RJSFSchema, UiSchema } from '@rjsf/utils';
import { FormattedMessage } from 'react-intl';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'array',
items: { type: 'string' },
};

const uiSchema: UiSchema = {
'ui:options': { copyable: true },
};

function CopyButton(props: IconButtonProps) {
const { icon, iconType, registry, uiSchema, ...btnProps } = props;
return (
<button type='button' {...btnProps}>
{icon} <FormattedMessage defaultMessage='Copy' />
</button>
);
}

render(
<Form
schema={schema}
uiSchema={uiSchema}
formData={['first', 'second']}
validator={validator}
templates={{ ButtonTemplates: { CopyButton } }}
/>,
document.getElementById('app'),
);

MoveDownButton​

The MoveDownButton is used to render a move down action on a Form for elements in an array. You can customize the MoveDownButton to render something other than the icon button that is provided by a theme as follows:

import React from 'react';
import { IconButtonProps, RJSFSchema } from '@rjsf/utils';
import { FormattedMessage } from 'react-intl';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'array',
items: { type: 'string' },
};

function MoveDownButton(props: IconButtonProps) {
const { icon, iconType, registry, uiSchema, ...btnProps } = props;
return (
<button type='button' {...btnProps}>
{icon} <FormattedMessage defaultMessage='Move Down' />
</button>
);
}

render(
<Form
schema={schema}
formData={['first', 'second']}
validator={validator}
templates={{ ButtonTemplates: { MoveDownButton } }}
/>,
document.getElementById('app'),
);

MoveUpButton​

The MoveUpButton is used to render a move up action on a Form for elements in an array. You can customize the MoveUpButton to render something other than the icon button that is provided by a theme as follows:

import React from 'react';
import { IconButtonProps, RJSFSchema } from '@rjsf/utils';
import { FormattedMessage } from 'react-intl';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'array',
items: { type: 'string' },
};

function MoveUpButton(props: IconButtonProps) {
const { icon, iconType, registry, uiSchema, ...btnProps } = props;
return (
<button type='button' {...btnProps}>
{icon} <FormattedMessage defaultMessage='Move Up' />
</button>
);
}

render(
<Form
schema={schema}
formData={['first', 'second']}
validator={validator}
templates={{ ButtonTemplates: { MoveUpButton } }}
/>,
document.getElementById('app'),
);

RemoveButton​

The RemoveButton is used to render a remove action on a Form for both a existing additionalProperties or patternProperties element for an object or an existing element in an array. You can customize the RemoveButton to render something other than the icon button that is provided by a theme as follows:

import React from 'react';
import { IconButtonProps, RJSFSchema } from '@rjsf/utils';
import { FormattedMessage } from 'react-intl';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'array',
items: { type: 'string' },
};

function RemoveButton(props: IconButtonProps) {
const { icon, iconType, registry, uiSchema, ...btnProps } = props;
return (
<button type='button' {...btnProps}>
{icon} <FormattedMessage defaultMessage='Remove' />
</button>
);
}

render(
<Form
schema={schema}
formData={['first', 'second']}
validator={validator}
templates={{ ButtonTemplates: { RemoveButton } }}
/>,
document.getElementById('app'),
);

SubmitButton​

The SubmitButton is already very customizable via the UISchemaSubmitButtonOptions capabilities in the uiSchema but it can also be fully customized as you see fit.

NOTE: However you choose to implement this, making it something other than a submit type button may result in the Form not submitting when pressed. You could also choose to provide your own submit button as the children prop of the Form should you so choose.

import React from 'react';
import { getSubmitButtonOptions, RJSFSchema, SubmitButtonProps } from '@rjsf/utils';
import { FormattedMessage } from 'react-intl';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
type: 'string',
};

function SubmitButton(props: SubmitButtonProps) {
const { uiSchema } = props;
const { norender } = getSubmitButtonOptions(uiSchema);
if (norender) {
return null;
}
return (
<button type='submit'>
<FormattedMessage defaultMessage='Okay' />
</button>
);
}

render(
<Form schema={schema} validator={validator} templates={{ ButtonTemplates: { SubmitButton } }} />,
document.getElementById('app'),
);

The following props are passed to a SubmitButton:

  • uiSchema: The uiSchema object for this field, used to extract the UISchemaSubmitButtonOptions.
  • registry: The registry object.
  • pending: Whether a submission is in flight: a promise onSubmit returned has yet to settle, or the form is pending in React's form status, as it is while a transition onSubmit started runs. Meanwhile the form sets aria-disabled and an onClick that cancels the click in the props of the UISchemaSubmitButtonOptions, so a button that spreads those props takes no second submit and stays focusable. Don't set disabled from pending, since the browser moves focus off a focused button that becomes disabled. Use pending to show the submission, such as with a spinner or a style for aria-disabled. See Submitting.

Registering Templates​

You can now add custom components to the registry and reference them in your uiSchema using string keys.

Adding Custom Templates to the Registry​

import CustomArrayFieldTemplate from './CustomArrayFieldTemplate';
import { UiSchema } from '@rjsf/utils';

// Add the custom template to the registry
const registry = { templates: { CustomArrayFieldTemplate } };

// Use the custom template in the uiSchema
const uiSchema: UiSchema = { 'ui:ArrayFieldTemplate': 'CustomArrayFieldTemplate' };

Reading a custom template back​

RJSF doesn't know the props of a template you register under your own name, so one read back from registry.templates or getTemplates() under that name has props of type never and can't be rendered as it is. Name its props with isComponentType(), which also checks that it is a component:

import { isComponentType, Registry } from '@rjsf/utils';
import { MyTemplateProps } from './MyTemplate';

function renderMyTemplate(registry: Registry, props: MyTemplateProps) {
const { MyTemplate } = registry.templates;
if (!isComponentType<MyTemplateProps>(MyTemplate)) {
return null;
}
return <MyTemplate {...props} />;
}

For a template in a group of your own, narrow the group first, since isComponentType() is false for it, then name the props on the member. A typeof check alone isn't enough to find the group, because what memo(), forwardRef() and lazy() return is an object too:

const { MyGroup } = registry.templates;
if (typeof MyGroup !== 'object' || isComponentType(MyGroup)) {
return null;
}
const { MyTemplate } = MyGroup;
if (!isComponentType<MyTemplateProps>(MyTemplate)) {
return null;
}
return <MyTemplate {...props} />;

A custom template written inline with no type on its props parameter takes never from the same entry, so give it one: templates={{ MyTemplate: (props: MyTemplateProps) => <div>{props.title}</div> }}.

Typing a set of templates​

PartialTemplatesType types a set of templates, as the templates prop of Form and a theme's templates take: it checks each template RJSF declares, such as FieldTemplate, against its own props, takes any of the ButtonTemplates on their own, and takes your own templates and groups of them beside those:

import { PartialTemplatesType } from '@rjsf/utils';
import MyFieldTemplate from './MyFieldTemplate';
import MySubmitButton from './MySubmitButton';
import MyTemplate from './MyTemplate';

const templates: PartialTemplatesType = {
FieldTemplate: MyFieldTemplate,
ButtonTemplates: { SubmitButton: MySubmitButton },
MyTemplate,
};

Partial<TemplatesType>, as every theme's generateTemplates() returns, checks the declared templates too, but Partial reaches only the top level, so a ButtonTemplates entry in it has to hold every button.

TemplatesType is two exported types put together: DeclaredTemplatesType holds the templates RJSF declares, and CustomTemplateEntries is the string index signature for your own. Omit with literal keys on TemplatesType or PartialTemplatesType, which has the same signature, such as Omit<TemplatesType, 'ButtonTemplates'>, collapses to that signature and checks none of the declared templates, so omit from DeclaredTemplatesType instead, and add CustomTemplateEntries when the type holds your own templates too. That signature takes a key you omitted unchecked, so declare it again with the type you want, such as a set that has to hold a FieldTemplate:

import { CustomTemplateEntries, DeclaredTemplatesType } from '@rjsf/utils';

type MyTemplates = Partial<Omit<DeclaredTemplatesType, 'FieldTemplate'>> & {
FieldTemplate: DeclaredTemplatesType['FieldTemplate'];
} & CustomTemplateEntries;

Pick keeps the templates it picks checked.