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

CheckboxesWidget should ensure that the value is an Array #2141

Closed
3 tasks done
ggrossetie opened this issue Nov 25, 2020 · 0 comments · Fixed by #3379
Closed
3 tasks done

CheckboxesWidget should ensure that the value is an Array #2141

ggrossetie opened this issue Nov 25, 2020 · 0 comments · Fixed by #3379

Comments

@ggrossetie
Copy link

Prerequisites

Description

CheckboxesWidget assumes that the value is an Array but does not check the type of the value.
At runtime, the widget will throw an exception when a value is selected or deselected.

Steps to Reproduce

See the codesandbox example: https://codesandbox.io/s/checkboxeswidget-with-non-array-value-react-jsonschema-form-qi96b?file=/src/App.js

Important parts:

var formData = {
  typeArticle: "Essai"
};

Expected behavior

The widget should check that the value is an Array. If not, the widget could either create an Array from the value or ignore the value.

Actual behavior

Throws an exception when the user is trying to select or deselect a value.
Please note that the value passed as a String will be correctly selected.

In the above example, the value "Essai" is selected (even if the value was Essai and not ["Essai"]):

selected

Version

2.4.0

heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 15, 2023
Fixes rjsf-team#2141 by reimplementing rjsf-team#2142

When the value passed to the `CheckboxesWidget` was a single value rather than an array, things would break in the control
- Updated the `CheckboxesWidget` in all themes but `antd` (which uses simpler logic) to fix ensure the value used in the helper functions is an array
- Added a test in `ArrayField_test.ts` that verifies the fix
- Updated the snapshot in `bootstrap-4` which showed an issue when the value string contained an element of the enumeration value rather than the whole value
- Updated the `CHANGELOG.md` accordingly
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 15, 2023
Fixes rjsf-team#2141 by reimplementing rjsf-team#2142

When the value passed to the `CheckboxesWidget` was a single value rather than an array, things would break in the control
- Updated the `CheckboxesWidget` in all themes but `antd` (which uses simpler logic) to fix ensure the value used in the helper functions is an array
- Added a test in `ArrayField_test.ts` that verifies the fix
- Updated the snapshot in `bootstrap-4` which showed an issue when the value string contained an element of the enumeration value rather than the whole value
- Updated the `CHANGELOG.md` accordingly
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 16, 2023
Fixes rjsf-team#2141 by reimplementing rjsf-team#2142

When the value passed to the `CheckboxesWidget` was a single value rather than an array, things would break in the control
- Updated the `CheckboxesWidget` in all themes but `antd` (which uses simpler logic) to fix ensure the value used in the helper functions is an array
- Added a test in `ArrayField_test.ts` that verifies the fix
- Updated the snapshot in `bootstrap-4` which showed an issue when the value string contained an element of the enumeration value rather than the whole value
- Refactored the common `selectValue` and `deselectValue` functions used in `CheckboxesWidget` into `@rjsf/utils`
- Updated the `CHANGELOG.md` accordingly
heath-freenome added a commit that referenced this issue Jan 16, 2023
* fix: Cast the value as an Array in CheckboxesWidget
Fixes #2141 by reimplementing #2142

When the value passed to the `CheckboxesWidget` was a single value rather than an array, things would break in the control
- Updated the `CheckboxesWidget` in all themes but `antd` (which uses simpler logic) to fix ensure the value used in the helper functions is an array
- Added a test in `ArrayField_test.ts` that verifies the fix
- Updated the snapshot in `bootstrap-4` which showed an issue when the value string contained an element of the enumeration value rather than the whole value
- Refactored the common `selectValue` and `deselectValue` functions used in `CheckboxesWidget` into `@rjsf/utils`
- Updated the `CHANGELOG.md` accordingly

* - Responded to reviewer feedback, including refactoring the `enumOptionsDeselectValue()` and `enumOptionsSelectValue()` from all the `CheckboxesWidget` implementations into `@rjsf/utils`
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this issue Jun 8, 2023
* fix: Cast the value as an Array in CheckboxesWidget
Fixes rjsf-team#2141 by reimplementing rjsf-team#2142

When the value passed to the `CheckboxesWidget` was a single value rather than an array, things would break in the control
- Updated the `CheckboxesWidget` in all themes but `antd` (which uses simpler logic) to fix ensure the value used in the helper functions is an array
- Added a test in `ArrayField_test.ts` that verifies the fix
- Updated the snapshot in `bootstrap-4` which showed an issue when the value string contained an element of the enumeration value rather than the whole value
- Refactored the common `selectValue` and `deselectValue` functions used in `CheckboxesWidget` into `@rjsf/utils`
- Updated the `CHANGELOG.md` accordingly

* - Responded to reviewer feedback, including refactoring the `enumOptionsDeselectValue()` and `enumOptionsSelectValue()` from all the `CheckboxesWidget` implementations into `@rjsf/utils`
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this issue Jun 8, 2023
* fix: Cast the value as an Array in CheckboxesWidget
Fixes rjsf-team#2141 by reimplementing rjsf-team#2142

When the value passed to the `CheckboxesWidget` was a single value rather than an array, things would break in the control
- Updated the `CheckboxesWidget` in all themes but `antd` (which uses simpler logic) to fix ensure the value used in the helper functions is an array
- Added a test in `ArrayField_test.ts` that verifies the fix
- Updated the snapshot in `bootstrap-4` which showed an issue when the value string contained an element of the enumeration value rather than the whole value
- Refactored the common `selectValue` and `deselectValue` functions used in `CheckboxesWidget` into `@rjsf/utils`
- Updated the `CHANGELOG.md` accordingly

* - Responded to reviewer feedback, including refactoring the `enumOptionsDeselectValue()` and `enumOptionsSelectValue()` from all the `CheckboxesWidget` implementations into `@rjsf/utils`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants