Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ it according to semantic versioning. For example, if your PR adds a breaking cha
should change the heading of the (upcoming) version to include a major version bump.

-->
# 6.0.0-beta.16

## @rjsf/antd

- Updated the `ArrayFieldTemplate`, `FieldTemplate` and `ObjectFieldTemplate` to get `formContext` from the `registry`

## @rjsf/core

- Updated `ArrayField`, `Form`, `LayoutMultiSchemaField` and `SchemaField` to stop passing `formContext`

## @rjsf/daisyui

- Updated `FieldTemplate` to remove `formContext` as it is never used

## @rjsf/semantic-ui

- Updated the `ArrayFieldTemplate`, `BaseInputTemplate`, `CheckboxWidget`, `FieldTemplate`, `RadioWidget`, `RangeSelect`, `SelectWidget`, `TextareaWidget` and `ObjectFieldTemplate` to get `formContext` from the `registry`

## @rjsf/utils

- BREAKING CHANGE: Removed `formContext` from the following interfaces because it is available on `registry`:
- `ErrorListProps`, `FieldProps`, `FieldTemplateProps`, `ArrayFieldTemplateProps` and `WidgetProps`

## Dev / docs / playground

- Updated the documentation to remove `formContext` from the interface documentation, adding a BREAKING CHANGE notification in the `v6.x upgrade guide`

# 6.0.0-beta.15

## @rjsf/chakra-ui
Expand Down
2 changes: 1 addition & 1 deletion packages/antd/src/templates/ArrayFieldTemplate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function ArrayFieldTemplate<
canAdd,
className,
disabled,
formContext,
idSchema,
items,
onAddClick,
Expand All @@ -57,6 +56,7 @@ export default function ArrayFieldTemplate<
registry,
uiOptions,
);
const { formContext } = registry;
// Button templates are not overridden in the uiSchema
const {
ButtonTemplates: { AddButton },
Expand Down
2 changes: 1 addition & 1 deletion packages/antd/src/templates/FieldTemplate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function FieldTemplate<
disabled,
displayLabel,
errors,
formContext,
help,
hidden,
id,
Expand All @@ -46,6 +45,7 @@ export default function FieldTemplate<
schema,
uiSchema,
} = props;
const { formContext } = registry;
const {
colon,
labelCol = VERTICAL_LABEL_COL,
Expand Down
2 changes: 1 addition & 1 deletion packages/antd/src/templates/ObjectFieldTemplate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default function ObjectFieldTemplate<
const {
description,
disabled,
formContext,
formData,
idSchema,
onAddClick,
Expand All @@ -57,6 +56,7 @@ export default function ObjectFieldTemplate<
registry,
uiOptions,
);
const { formContext } = registry;
// Button templates are not overridden in the uiSchema
const {
ButtonTemplates: { AddButton },
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ export default class Form<
/** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */
renderErrors(registry: Registry<T, S, F>) {
const { errors, errorSchema, schema, uiSchema } = this.state;
const { formContext } = this.props;
const options = getUiOptions<T, S, F>(uiSchema);
const ErrorListTemplate = getTemplate<'ErrorListTemplate', T, S, F>('ErrorListTemplate', registry, options);

Expand All @@ -608,7 +607,6 @@ export default class Form<
errorSchema={errorSchema || {}}
schema={schema}
uiSchema={uiSchema}
formContext={formContext}
registry={registry}
/>
);
Expand Down Expand Up @@ -1117,7 +1115,6 @@ export default class Form<
noHtml5Validate = false,
disabled,
readonly,
formContext,
showErrorList = 'top',
_internalFormWrapper,
} = this.props;
Expand Down Expand Up @@ -1163,7 +1160,6 @@ export default class Form<
idSchema={idSchema}
idPrefix={idPrefix}
idSeparator={idSeparator}
formContext={formContext}
formData={formData}
onChange={this.onChange}
onBlur={this.onBlur}
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/components/fields/ArrayField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
required,
schema,
title: fieldTitle,
formContext,
formData,
rawErrors,
registry,
Expand Down Expand Up @@ -832,7 +831,6 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
schema,
uiSchema,
title: fieldTitle,
formContext,
errorSchema,
rawErrors,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ export default function LayoutMultiSchemaField<
label={(title || schema.title) ?? ''}
disabled={disabled || (Array.isArray(enumOptions) && isEmpty(enumOptions))}
uiSchema={uiSchema}
formContext={formContext}
required={required}
readonly={!!readonly}
registry={registry}
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/components/fields/SchemaField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
displayLabel,
classNames: classNames.join(' ').trim(),
style: uiOptions.style,
formContext,
formData,
schema,
uiSchema,
Expand Down
10 changes: 8 additions & 2 deletions packages/core/test/ArrayField.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2988,7 +2988,10 @@ describe('ArrayField', () => {
root_1: 'root_1-id',
};
function CustomSchemaField(props) {
const { formContext, idSchema } = props;
const {
registry: { formContext },
idSchema,
} = props;
return (
<>
<code id={formContext[idSchema.$id]}>Ha</code>
Expand All @@ -3015,7 +3018,10 @@ describe('ArrayField', () => {
root_1: 'root_1-id',
};
function CustomSchemaField(props) {
const { formContext, idSchema } = props;
const {
registry: { formContext },
idSchema,
} = props;
return (
<>
<code id={formContext[idSchema.$id]}>Ha</code>
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/FormContext.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('FormContext', () => {
});

it('should be passed to TemplateField', () => {
function CustomTemplateField({ formContext }) {
function CustomTemplateField({ registry: { formContext } }) {
return <div id={formContext.foo} />;
}

Expand All @@ -79,7 +79,7 @@ describe('FormContext', () => {
});

it('should be passed to ArrayTemplateField', () => {
function CustomArrayTemplateField({ formContext }) {
function CustomArrayTemplateField({ registry: { formContext } }) {
return <div id={formContext.foo} />;
}

Expand Down
5 changes: 4 additions & 1 deletion packages/core/test/ObjectField.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ describe('ObjectField', () => {
root_bar: 'bar-id',
};
function CustomSchemaField(props) {
const { formContext, idSchema } = props;
const {
registry: { formContext },
idSchema,
} = props;
return (
<>
<code id={formContext[idSchema.$id]}>Ha</code>
Expand Down
5 changes: 4 additions & 1 deletion packages/core/test/allOf.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ describe('allOf', () => {
};
const formContext = { root: 'root-id', root_foo: 'foo-id' };
function CustomSchemaField(props) {
const { formContext, idSchema } = props;
const {
registry: { formContext },
idSchema,
} = props;
return (
<>
<code id={formContext[idSchema.$id]}>Ha</code>
Expand Down
5 changes: 4 additions & 1 deletion packages/core/test/oneOf.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,10 @@ describe('oneOf', () => {
const formContext = { root: 'root-id', root_userId: 'userId-id' };

function CustomSchemaField(props) {
const { formContext, idSchema } = props;
const {
registry: { formContext },
idSchema,
} = props;
return (
<>
<code id={formContext[idSchema.$id]}>Ha</code>
Expand Down
10 changes: 9 additions & 1 deletion packages/core/test/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,15 @@ describe('Validation', () => {

const formData = 0;

const CustomErrorList = ({ errors, errorSchema, schema, uiSchema, formContext: { className } }) => (
const CustomErrorList = ({
errors,
errorSchema,
schema,
uiSchema,
registry: {
formContext: { className },
},
}) => (
<div>
<div className='CustomErrorList'>{errors.length} custom</div>
<div className={'ErrorSchema'}>{errorSchema.__errors[0]}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function FieldTemplate<
label,
children,
errors,
formContext,
formData,
help,
hideError,
Expand Down
6 changes: 0 additions & 6 deletions packages/docs/docs/advanced-customization/custom-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ The following props are passed to each `ArrayFieldTemplate`:
- `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.
- `formContext`: The `formContext` object that you passed to Form.
- `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`
- `rawErrors`: An array of strings listing all generated error messages from encountered errors for this widget
Expand Down Expand Up @@ -419,7 +418,6 @@ function BaseInputTemplate(props: BaseInputTemplateProps) {
hideError,
uiSchema,
registry,
formContext,
...rest
} = props;
const onTextChange = ({ target: { value: val } }: ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -500,7 +498,6 @@ The following props are passed to the `BaseInputTemplate`:
- `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](./custom-widgets-fields.md#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.
- `formContext`: The `formContext` object that you passed to `Form`.
- `rawErrors`: An array of strings listing all generated error messages from encountered errors for this widget.
- `registry`: The `registry` object

Expand Down Expand Up @@ -587,7 +584,6 @@ The following props are passed to the `ErrorListTemplate`:

- `schema`: The schema that was passed to `Form`
- `uiSchema`: The uiSchema that was passed to `Form`
- `formContext`: The `formContext` object that you passed to `Form`.
- `errors`: An array of all errors in this `Form`.
- `errorSchema`: The `ErrorSchema` constructed by `Form`

Expand Down Expand Up @@ -755,7 +751,6 @@ The following props are passed to a custom field template component:
- `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.
- `formContext`: The `formContext` object that you passed to `Form`.
- `formData`: The formData for this field.
- `registry`: The `registry` object.

Expand Down Expand Up @@ -926,7 +921,6 @@ The following props are passed to each `ObjectFieldTemplate` as defined by the `
- `idSchema`: An object containing the id for this object & ids for its properties.
- `errorSchema`: The optional validation errors in the form of an `ErrorSchema`
- `formData`: The form data for the object.
- `formContext`: The `formContext` object that you passed to Form.
- `registry`: The `registry` object.

The following props are part of each element in `properties`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ The following props are passed to custom widget components:
- `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](#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.
- `formContext`: The `formContext` object that you passed to `Form`.
- `rawErrors`: An array of strings listing all generated error messages from encountered errors for this widget.
- `registry`: A [registry](#the-registry-object) object (read next).

Expand Down Expand Up @@ -393,7 +392,6 @@ A field component will always be passed the following props:
- `formData`: The data for this field;
- `errorSchema`: The tree of errors for this field and its children;
- `registry`: A [registry](#the-registry-object) object (read next).
- `formContext`: A [formContext](../api-reference/form-props.md#formcontext) object (read next).
- `required`: The required status of this field;
- `disabled`: A boolean value stating if the field is disabled;
- `readonly`: A boolean value stating if the field is read-only;
Expand All @@ -413,7 +411,6 @@ The `registry` is an object containing the registered core, theme and custom fie
- `fields`: The set of all fields used by the `Form`. Includes fields from `core`, theme-specific fields and any [custom registered fields](#custom-field-components);
- `widgets`: The set of all widgets used by the `Form`. Includes widgets from `core`, theme-specific widgets and any [custom registered widgets](#custom-component-registration), if any;
- `rootSchema`: The root schema, as passed to the `Form`, which can contain referenced [definitions](../json-schema/definitions.md);
- `formContext`: The [formContext](../api-reference/form-props.md#formcontext) that was passed to `Form`;
- `schemaUtils`: The current implementation of the `SchemaUtilsType` (from `@rjsf/utils`) in use by the `Form`. Used to call any of the validation-schema-based utility functions.

The registry is passed down the component tree, so you can access it from your custom field, custom widget, custom template and `SchemaField` components.
Expand Down
13 changes: 13 additions & 0 deletions packages/docs/docs/migration-guides/v6.x upgrade guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ React 18 is officially supported on all the themes.

React 19 support is expected before the end of beta (although several developers have already upgraded with no problems).

### formContext BREAKING CHANGES

Removed the unnecessary `formContext` property from the following interfaces since it is readily available in the `registry`.
If you were using the `formContext` in your custom `template`, `field` or `widget`, simply get it from the `registry` instead.

Interfaces with `formContext` removed:

- `ErrorListProps` - The properties that are passed to an `ErrorListTemplate` implementation
- `FieldProps` - The properties that are passed to a `Field` implementation
- `FieldTemplateProps` - The properties that are passed to a `FieldTemplate` implementation
- `ArrayFieldTemplateProps` - The properties that are passed to an `ArrayFieldTemplate` implementation
- `WidgetProps` - The properties that are passed to a `Widget` implementation

### Fields BREAKING CHANGES

### FieldProps.onChange
Expand Down
Loading