Custom field, array and object templates take their error state from hasErrors
Detect
- In your custom
FieldTemplate: props forwarded toWrapIfAdditionalTemplateone by one, withouthasErrors. - In the type checker:
Property 'hasErrors' is missing in type '{ schema: JSONSchema7; … }' but required in type 'Pick<FieldTemplateProps<unknown, JSONSchema7, object>, …>'., under aTS2769"No overload matches this call." on theWrapIfAdditionalTemplateelement. - In plain JavaScript: an extra key's wrapper has lost its
has-errorclass. - In your custom
FieldTemplate,ArrayFieldTemplateorObjectFieldTemplate: an error state read fromrawErrors. - In the console: React warns about an unknown
errorschemaattribute from a template that spreads its leftover props onto a DOM node.
Change
WrapIfAdditionalTemplateProps picks hasErrors as a required prop, and core's WrapIfAdditionalTemplate takes its has-error class from it alone. Add it to the list, beside keyName and propertyNamesEnum:
<WrapIfAdditionalTemplate
classNames={classNames}
keyName={keyName}
+ hasErrors={hasErrors}
...
>
A template's rawErrors is deprecated. Take the error state from its hasErrors prop, which holds whether the field has errors to show with ui:hideError applied. SchemaField withholds rawErrors from the FieldTemplate while the errors are hidden, as it always has, and now does so for a layout grid's discriminated cell too.
ArrayFieldTemplate and ObjectFieldTemplate are handed their own errors as rawErrors whatever hideError says, as a widget is, and that rawErrors is deprecated too. They take their error state from their own hasErrors, and the messages they draw from getErrorsToDraw(). That gives presentation.errors.messages only where presentation.errors.by is 'self', since the FieldTemplate draws them under 'template'; see A custom FieldTemplate draws what the plan hands it.
A FieldTemplate gains errorSchema, which ArrayFieldTemplateProps and ObjectFieldTemplateProps already declared. It carries every error whatever hideError says, so a template that renders the errors itself can reach the ones the directive withholds. A template that spreads its leftover props onto a DOM node destructures errorSchema out with the rest.
A discriminated layout grid cell's template is now handed classNames and style, so its wrapper carries rjsf-field-error while the field has errors to show; see A discriminated layout grid cell renders inside a full field wrapper.
Verify
- Your templates compile, an extra key's wrapper carries
has-errorwhile it has errors to show, and nothing readsrawErrorsfor error state. - React logs no unknown-attribute warning for
errorschema.
Also read:
- A custom widget or theme takes its error state from hasWidgetErrors
- FieldTemplateProps requires keyName
- A custom field that renders FieldTemplate itself passes hasErrors
- A discriminated layout grid cell renders inside a full field wrapper
- A custom FieldTemplate, ObjectFieldTemplate or ArrayFieldTemplate draws what the plan hands it