Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: BooleanField component to not alter readOnly props #3188

Merged
merged 3 commits into from
Oct 7, 2022
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
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ should change the heading of the (upcoming) version to include a major version b
## @rjsf/core
- Extended `Form.onChange` to optionally return the `id` of the field that caused the change, fixing [#2768](https://github.com/rjsf-team/react-jsonschema-form/issues/2768)
- Fixed a regression in earlier v5 beta versions where additional properties could not be added when `additionalProperties` was `true` ([#3719](https://github.com/rjsf-team/react-jsonschema-form/pull/3719)).

- Fixed a regression in v5 beta version where BooleanField was altering readonly props ([#3188](https://github.com/rjsf-team/react-jsonschema-form/pull/3188).
-
## @rjsf/utils
- Updated the `onChange` prop on `FieldProps` and `FieldTemplateProps` to add an optional `id` parameter to the callback.

Expand Down Expand Up @@ -56,7 +57,7 @@ should change the heading of the (upcoming) version to include a major version b
- Fixed `CheckboxesWidget` and `RadioWidget` to have unique `id`s for each radio element by appending the `option.value`, removing unnecessary casts to `any` and protecting against non-arrays

## @rjsf/core
- Convert `WrapIfAdditional` to `WrapIfAdditionalTemplate`
- Convert `WrapIfAdditional` to `WrapIfAdditionalTemplate`
- Added `name` to the `input` components that were missing it to support `remix`
- Fixed `CheckboxesWidget` and `RadioWidget` to have unique `id`s for each radio element by appending the `option.value`
- Updated the `validate()` method on `Form` to make `schemaUtils` an optional third parameter rather than a required first parameter, making the signature backwards compatible with what was provided in previous versions.
Expand Down Expand Up @@ -103,7 +104,7 @@ should change the heading of the (upcoming) version to include a major version b
- Pass `uiSchema` appropriately to all of the `IconButton`s, `ArrayFieldItemTemplate` and `WrapIfAdditional` components, fixing (https://github.com/rjsf-team/react-jsonschema-form/issues/3130)

## @rjsf/core
- Updated the `FieldErrorTemplate` to remove the explicit typing of the `error` to string to support the two options
- Updated the `FieldErrorTemplate` to remove the explicit typing of the `error` to string to support the two options
- Implemented programmatic validation via new `validateForm()` method on `Form`, fixing (https://github.com/rjsf-team/react-jsonschema-form/issues/2755, https://github.com/rjsf-team/react-jsonschema-form/issues/2552, https://github.com/rjsf-team/react-jsonschema-form/issues/2381, https://github.com/rjsf-team/react-jsonschema-form/issues/2343, https://github.com/rjsf-team/react-jsonschema-form/issues/1006, https://github.com/rjsf-team/react-jsonschema-form/issues/246)
- Renamed `WithThemeProps` to `ThemeProps` to prevent another breaking-change by returning the type back to the name it had in version 4
- Pass `uiSchema` appropriately to all of the `IconButton`s, `ArrayFieldItemTemplate` and `WrapIfAdditional` components, fixing (https://github.com/rjsf-team/react-jsonschema-form/issues/3130)
Expand All @@ -124,7 +125,7 @@ should change the heading of the (upcoming) version to include a major version b
## @rjsf/semantic-ui
- Updated the `FieldErrorTemplate` to use the `children` variation of the `List.Item` that supports ReactElement
- Pass `uiSchema` appropriately to all of the `IconButton`s, `ArrayFieldItemTemplate` and `WrapIfAdditional` components, fixing (https://github.com/rjsf-team/react-jsonschema-form/issues/3130)

## @rjsf/utils
- Updated the `FieldErrorProps` type to make it support an array of string and ReactElement
- Updated the `IconButtonProps` type to add `uiSchema`, adding the `<T = any, F = any>` generics to it and the associated `ButtonTemplates` in `TemplatesType` AND added `uiSchema` to `ArrayFieldTemplateItemType` as well, fixing (https://github.com/rjsf-team/react-jsonschema-form/issues/3130)
Expand Down Expand Up @@ -196,7 +197,7 @@ should change the heading of the (upcoming) version to include a major version b
- Fixed the `README.md` to correct the package name in several places to match the actual package

## @rjsf/validator-ajv8
- Support for localization (L12n) on a customized validator using a `Localizer` function passed as a second parameter to `customizeValidator()`, fixing (https://github.com/rjsf-team/react-jsonschema-form/pull/846, and https://github.com/rjsf-team/react-jsonschema-form/issues/1195)
- Support for localization (L12n) on a customized validator using a `Localizer` function passed as a second parameter to `customizeValidator()`, fixing (https://github.com/rjsf-team/react-jsonschema-form/pull/846, and https://github.com/rjsf-team/react-jsonschema-form/issues/1195)
- Fixed the `README.md` to correct the package name in several places to match the actual package

## Dev / docs / playground
Expand Down
17 changes: 8 additions & 9 deletions packages/core/src/components/fields/BooleanField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,25 @@ function BooleanField<T = any, F = any>(props: FieldProps<T, F>) {
} else {
// We deprecated enumNames in v5. It's intentionally omitted from RSJFSchema type, so we need to cast here.
const schemaWithEnumNames = schema as RJSFSchema & { enumNames?: string[] };
schema.enum = schema.enum ?? [true, false];
const enums = schema.enum ?? [true, false];
if (
!schemaWithEnumNames.enumNames &&
schema.enum &&
schema.enum.length === 2 &&
schema.enum.every((v) => typeof v === "boolean")
enums.length === 2 &&
enums.every((v) => typeof v === "boolean")
) {
enumOptions = [
{
value: schema.enum[0],
label: schema.enum[0] ? "Yes" : "No",
value: enums[0],
label: enums[0] ? "Yes" : "No",
},
{
value: schema.enum[1],
label: schema.enum[1] ? "Yes" : "No",
value: enums[1],
label: enums[1] ? "Yes" : "No",
},
];
} else {
enumOptions = optionsList({
enum: schema.enum,
enum: enums,
// NOTE: enumNames is deprecated, but still supported for now.
enumNames: schemaWithEnumNames.enumNames,
} as RJSFSchema);
Expand Down