diff --git a/CHANGELOG.md b/CHANGELOG.md index 62a7027bbb..a57446511d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ should change the heading of the (upcoming) version to include a major version b --> # 6.0.0-beta.15 +## @rjsf/core + +- Updated `ArrayField` `onSelectChange` to not pass `name` in the `path` since the `ObjectField` will automatically add it [#4733](https://github.com/rjsf-team/react-jsonschema-form/issues/4733) + ## @rjsf/semantic-ui - Updated `ArrayField` to stop using `nanoid` and instead use `lodash/uniqueId` to fix [#4762](https://github.com/rjsf-team/react-jsonschema-form/issues/4726) diff --git a/packages/core/src/components/fields/ArrayField.tsx b/packages/core/src/components/fields/ArrayField.tsx index 0427888eda..ff6bea1d35 100644 --- a/packages/core/src/components/fields/ArrayField.tsx +++ b/packages/core/src/components/fields/ArrayField.tsx @@ -418,9 +418,9 @@ class ArrayField { - const { name, onChange, idSchema } = this.props; - // select change will pass the `path` array with the name - onChange(value, [name], undefined, idSchema && idSchema.$id); + const { onChange, idSchema } = this.props; + // select change will pass an empty `path` array since the `ObjectField` will add the path value automatically + onChange(value, [], undefined, idSchema && idSchema.$id); }; /** Helper method to compute item UI schema for both normal and fixed arrays diff --git a/packages/utils/src/idGenerators.ts b/packages/utils/src/idGenerators.ts index 6d3821b39c..23c5cc67c9 100644 --- a/packages/utils/src/idGenerators.ts +++ b/packages/utils/src/idGenerators.ts @@ -1,7 +1,7 @@ import isString from 'lodash/isString'; -import { IdSchema } from './types'; import { ID_KEY } from './constants'; +import { IdSchema } from './types'; /** Generates a consistent `id` pattern for a given `id` and a `suffix` * @@ -86,6 +86,9 @@ export function optionId(id: string, optionIndex: number) { * @param btn - The button type for which to generate the id * @returns - The consistent id for the button from the given `id` and `btn` type */ -export function buttonId(id: IdSchema | string, btn: 'add' | 'copy' | 'moveDown' | 'moveUp' | 'remove') { +export function buttonId( + id: IdSchema | string, + btn: 'add' | 'copy' | 'moveDown' | 'moveUp' | 'remove' | 'copy-from-parent', +) { return idGenerator(id, btn); } diff --git a/packages/utils/src/types.ts b/packages/utils/src/types.ts index 3f5806b35b..6cc5edae5a 100644 --- a/packages/utils/src/types.ts +++ b/packages/utils/src/types.ts @@ -1,3 +1,4 @@ +import { JSONSchema7 } from 'json-schema'; import type { ButtonHTMLAttributes, ChangeEvent, @@ -7,7 +8,6 @@ import type { ReactNode, StyleHTMLAttributes, } from 'react'; -import { JSONSchema7 } from 'json-schema'; import { TranslatableString } from './enums'; @@ -640,6 +640,9 @@ export type ArrayFieldItemButtonsTemplateType< onReorderClick: (index: number, newIndex: number) => (event?: any) => void; /** A boolean value stating if the array item is read-only */ readonly?: boolean; + /** CUSTOM */ + hasCopyFromParent?: boolean; + onCopyFromParentIndexClick?: (index: number) => (event?: any) => void; }; /** The properties of each element in the ArrayFieldTemplateProps.items array */ @@ -1065,6 +1068,7 @@ export type CustomValidator = ( errors: RJSFValidationError[], uiSchema?: UiSchema, + formData?: T | undefined, ) => RJSFValidationError[]; /** The type that describes the data that is returned from the `ValidatorType.validateFormData()` function */ diff --git a/packages/validator-ajv8/src/processRawValidationErrors.ts b/packages/validator-ajv8/src/processRawValidationErrors.ts index 9906f8e43a..51a3895a57 100644 --- a/packages/validator-ajv8/src/processRawValidationErrors.ts +++ b/packages/validator-ajv8/src/processRawValidationErrors.ts @@ -1,5 +1,3 @@ -import { ErrorObject } from 'ajv'; -import get from 'lodash/get'; import { createErrorHandler, CustomValidator, @@ -17,6 +15,8 @@ import { validationDataMerge, ValidatorType, } from '@rjsf/utils'; +import { ErrorObject } from 'ajv'; +import get from 'lodash/get'; export type RawValidationErrorsType = { errors?: Result[]; @@ -140,7 +140,7 @@ export default function processRawValidationErrors< errors = [...errors, { stack: invalidSchemaError!.message }]; } if (typeof transformErrors === 'function') { - errors = transformErrors(errors, uiSchema); + errors = transformErrors(errors, uiSchema, formData); } let errorSchema = toErrorSchema(errors);