-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Default value of field dependent on drop down not being updated #2978
Comments
I'm running into similar issues. I think the cause is here: react-jsonschema-form/packages/utils/src/schema/getDefaultFormState.ts Lines 106 to 141 in b63ec99
When computing the defaults, once one set of defaults is determined, it only recurses down to non-dependent properties. |
Looking into this a bit more, it's less clear to me that this is a bug. FormData would need to record the source of every field (set from a default or entered data). Slightly altering the example playground with |
The example I've been looking at is here, with a recursive definition with dependencies. To reproduce on that playground:
A related schema (which should be semantically equivalent) puts the default on the |
I'm wondering if this is a very complicated example of #2944 in that our oneOf code isn't properly selecting the correct one-of |
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()`
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()`
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()`
* 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
* 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
* 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
Prerequisites
What theme are you using?
core
Version
Playground
Current Behavior
In a form with two fields, where one is a dropdown of different options and a second is dependent on the other. The second field changes values depending on the option second. If you then select a different option from the dropdown menu, the value of the second field does not change to the different value.
Expected Behavior
In a form with two fields, where one is a dropdown of different options and a second is dependent on the other. The second field changes values depending on the option second. If you then select a different option from the dropdown menu, the value of the second field would change to the different value.
Steps To Reproduce
In the React JSON Schema playground, create a form using the following payload
Select value1 from the Component menu and notice the value of the template field is abc
Then select value2 from the Component menu and notice the value of the template field is abc (and not the expected def)
Environment
Anything else?
Playground link here
The text was updated successfully, but these errors were encountered: