Skip to content
Draft
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/components/fields/ArrayField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For

/** Callback handler used to change the value for a checkbox */
onSelectChange = (value: any) => {
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
Expand Down
7 changes: 5 additions & 2 deletions packages/utils/src/idGenerators.ts
Original file line number Diff line number Diff line change
@@ -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`
*
Expand Down Expand Up @@ -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<T = any>(id: IdSchema<T> | string, btn: 'add' | 'copy' | 'moveDown' | 'moveUp' | 'remove') {
export function buttonId<T = any>(
id: IdSchema<T> | string,
btn: 'add' | 'copy' | 'moveDown' | 'moveUp' | 'remove' | 'copy-from-parent',
) {
return idGenerator<T>(id, btn);
}
6 changes: 5 additions & 1 deletion packages/utils/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { JSONSchema7 } from 'json-schema';
import type {
ButtonHTMLAttributes,
ChangeEvent,
Expand All @@ -7,7 +8,6 @@ import type {
ReactNode,
StyleHTMLAttributes,
} from 'react';
import { JSONSchema7 } from 'json-schema';

import { TranslatableString } from './enums';

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -1065,6 +1068,7 @@ export type CustomValidator<T = any, S extends StrictRJSFSchema = RJSFSchema, F
export type ErrorTransformer<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = (
errors: RJSFValidationError[],
uiSchema?: UiSchema<T, S, F>,
formData?: T | undefined,
) => RJSFValidationError[];

/** The type that describes the data that is returned from the `ValidatorType.validateFormData()` function */
Expand Down
6 changes: 3 additions & 3 deletions packages/validator-ajv8/src/processRawValidationErrors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ErrorObject } from 'ajv';
import get from 'lodash/get';
import {
createErrorHandler,
CustomValidator,
Expand All @@ -17,6 +15,8 @@ import {
validationDataMerge,
ValidatorType,
} from '@rjsf/utils';
import { ErrorObject } from 'ajv';
import get from 'lodash/get';

export type RawValidationErrorsType<Result = any> = {
errors?: Result[];
Expand Down Expand Up @@ -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<T>(errors);
Expand Down