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

OneOf with array as subschema is failling with any rjsf theme #2375

Open
3 tasks done
Ugolaf opened this issue May 11, 2021 · 1 comment
Open
3 tasks done

OneOf with array as subschema is failling with any rjsf theme #2375

Ugolaf opened this issue May 11, 2021 · 1 comment
Assignees
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf arrays bug

Comments

@Ugolaf
Copy link

Ugolaf commented May 11, 2021

Prerequisites

shared playground link of bug

Description

I'm trying to have a multiple-choice select with a dependency for one or more values.

There are 3 choices: A, B, or C.
So there is exactly 7 differents possibilities + the empty possibility:
A
B
C
A, B
A, C
B, C
A, B, C

Dependencies are working but if you select C then B within a theme (for example material UI theme), oneOf is failing because he doesn't match to [B, C] because its value is [C, B].

Steps to Reproduce

  1. Go to shared playground link of bug
  2. Open log in your browser
  3. Select C then B

Expected behavior

As it's happening without a specific theme on rjsf, [C, B] will match to [B, C] array.

Actual behavior

ignoring oneOf in dependencies because there isn't exactly one subschema that is valid

[C, B] is different from [B, C] for oneOf. It must match if the array contains the same things. Or it will be really heavy for A, B, C choice to define oneOf 14 possibilities for that example :
A
B
C
A, B
B, A
A, C
C, A
B, C
C, B
A, B, C
B, A, C
B, C, A
C, B, A
C, A, B

I also tried to reorder the formdata array but the error is happening before onChange trigger.

Version

"@rjsf/core": "^2.5.1",
"@rjsf/material-ui": "^2.5.1",

@xyy7260
Copy link

xyy7260 commented May 27, 2021

@Ugolaf I also encountered this problem, did you solve it in the end? But I need to choose ['a','b','c'] then a, b, and c must appear at the same time

@jacqueswho jacqueswho added the bug label Feb 22, 2022
@heath-freenome heath-freenome added arrays any-one-all-of Related to fixing anyOf, oneOf or allOf labels Jan 20, 2023
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 21, 2023
…jsf-team#2375

- Also updated the `CHANGELOG.md` to include all of the fixed issues
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 23, 2023
…jsf-team#2375

- Also updated the `CHANGELOG.md` to include all of the fixed issues
heath-freenome added a commit that referenced this issue Jan 24, 2023
* fix: fixed several issue in oneOf/anyOf functions
Fixes #2944, #3236, #2978 and possibly others
- In `@rjsf/utils`, added new `getClosestMatchingOption()`, `getFirstMatchingOption()` and `sanitizeDataForNewSchema()` schema-based utility functions
  - Deprecated `getMatchingOption()` and updated all calls to it in other utility functions to use `getFirstMatchingOption()`
  - Added 100% unit tests for all new functions, renaming the old `getMatchingOptionsTest.ts` file to `getFirstMatchingOptionsTest.ts`
  - Updated `createSchemaUtils()` and it's associated type to add the three new functions
- In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8`, updated the `schema.tests.ts` to add the new tests for the new schema-based utility functions
- In `@rjsf/core`, updated the `MultiSchemaField` to use the new `getClosestMatchingOption()` and `sanitizeDataForNewSchema()` utility functions
  - Also updated the render to properly pass props to the widget and the schema field
- In `@rjsf/playground`, updated `onFormDataEdited()` to only change the formData in the state if the `JSON.stringify()` of the old and new values are different
  - Also updated the `npm start` command to add the `--force` option to avoid issues where changes made to other packages weren't getting picked up due to `vite` caching
- Updated the `utility-functions.md` file to document the new schema-based functions and to fix up incorrect strike-through caused by the unescaped `<S>` generic
- Updated the `5.x upgrade guide.md` file to document the new utility functions and the deprecation of `getMatchingOption()`

* - Fixed a few small issues exposed by trying to use the playground in #2375
- Also updated the `CHANGELOG.md` to include all of the fixed issues

* - Fix #2538 by fixing additionalProperties to deal with allOf/anyOf/oneOf

* - Updated `getSchemaType()` to grab the type of the first element of a `oneOf`/`anyOf`

* - Allow `formData` in `getClosestMatchingOption()` to accept `undefined`

* - Responded to reviewer feedback

* - Deal with sanitizing data when both `array.items` elements are booleans and have the same value

* - Fixed issue with const being assigned default value incorrectly and handle readOnly default values like const
- Updated some documentation in the types and createSchemaUtils
@heath-freenome heath-freenome self-assigned this Jan 25, 2023
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this issue Jun 8, 2023
* fix: fixed several issue in oneOf/anyOf functions
Fixes rjsf-team#2944, rjsf-team#3236, rjsf-team#2978 and possibly others
- In `@rjsf/utils`, added new `getClosestMatchingOption()`, `getFirstMatchingOption()` and `sanitizeDataForNewSchema()` schema-based utility functions
  - Deprecated `getMatchingOption()` and updated all calls to it in other utility functions to use `getFirstMatchingOption()`
  - Added 100% unit tests for all new functions, renaming the old `getMatchingOptionsTest.ts` file to `getFirstMatchingOptionsTest.ts`
  - Updated `createSchemaUtils()` and it's associated type to add the three new functions
- In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8`, updated the `schema.tests.ts` to add the new tests for the new schema-based utility functions
- In `@rjsf/core`, updated the `MultiSchemaField` to use the new `getClosestMatchingOption()` and `sanitizeDataForNewSchema()` utility functions
  - Also updated the render to properly pass props to the widget and the schema field
- In `@rjsf/playground`, updated `onFormDataEdited()` to only change the formData in the state if the `JSON.stringify()` of the old and new values are different
  - Also updated the `npm start` command to add the `--force` option to avoid issues where changes made to other packages weren't getting picked up due to `vite` caching
- Updated the `utility-functions.md` file to document the new schema-based functions and to fix up incorrect strike-through caused by the unescaped `<S>` generic
- Updated the `5.x upgrade guide.md` file to document the new utility functions and the deprecation of `getMatchingOption()`

* - Fixed a few small issues exposed by trying to use the playground in rjsf-team#2375
- Also updated the `CHANGELOG.md` to include all of the fixed issues

* - Fix rjsf-team#2538 by fixing additionalProperties to deal with allOf/anyOf/oneOf

* - Updated `getSchemaType()` to grab the type of the first element of a `oneOf`/`anyOf`

* - Allow `formData` in `getClosestMatchingOption()` to accept `undefined`

* - Responded to reviewer feedback

* - Deal with sanitizing data when both `array.items` elements are booleans and have the same value

* - Fixed issue with const being assigned default value incorrectly and handle readOnly default values like const
- Updated some documentation in the types and createSchemaUtils
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this issue Jun 8, 2023
* fix: fixed several issue in oneOf/anyOf functions
Fixes rjsf-team#2944, rjsf-team#3236, rjsf-team#2978 and possibly others
- In `@rjsf/utils`, added new `getClosestMatchingOption()`, `getFirstMatchingOption()` and `sanitizeDataForNewSchema()` schema-based utility functions
  - Deprecated `getMatchingOption()` and updated all calls to it in other utility functions to use `getFirstMatchingOption()`
  - Added 100% unit tests for all new functions, renaming the old `getMatchingOptionsTest.ts` file to `getFirstMatchingOptionsTest.ts`
  - Updated `createSchemaUtils()` and it's associated type to add the three new functions
- In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8`, updated the `schema.tests.ts` to add the new tests for the new schema-based utility functions
- In `@rjsf/core`, updated the `MultiSchemaField` to use the new `getClosestMatchingOption()` and `sanitizeDataForNewSchema()` utility functions
  - Also updated the render to properly pass props to the widget and the schema field
- In `@rjsf/playground`, updated `onFormDataEdited()` to only change the formData in the state if the `JSON.stringify()` of the old and new values are different
  - Also updated the `npm start` command to add the `--force` option to avoid issues where changes made to other packages weren't getting picked up due to `vite` caching
- Updated the `utility-functions.md` file to document the new schema-based functions and to fix up incorrect strike-through caused by the unescaped `<S>` generic
- Updated the `5.x upgrade guide.md` file to document the new utility functions and the deprecation of `getMatchingOption()`

* - Fixed a few small issues exposed by trying to use the playground in rjsf-team#2375
- Also updated the `CHANGELOG.md` to include all of the fixed issues

* - Fix rjsf-team#2538 by fixing additionalProperties to deal with allOf/anyOf/oneOf

* - Updated `getSchemaType()` to grab the type of the first element of a `oneOf`/`anyOf`

* - Allow `formData` in `getClosestMatchingOption()` to accept `undefined`

* - Responded to reviewer feedback

* - Deal with sanitizing data when both `array.items` elements are booleans and have the same value

* - Fixed issue with const being assigned default value incorrectly and handle readOnly default values like const
- Updated some documentation in the types and createSchemaUtils
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf arrays bug
Projects
None yet
Development

No branches or pull requests

4 participants