You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: made small changes to utility functions to fix#3997, #4314 and #4322 (#4329)
* Fix: made small changes to utility functions to fix#3997 and #4322Fixes#3997 and #4322
- In `@rjsf/utils`, made the following changes:
- Updated `mergeDefaultsWithFormData()` to not overwrite a default when the formData has an undefined value
- Updated `getClosestMatchingOption()` to improve the scoring function so that an object container that matches a key gets an extra point
- In `@rjsf/core`, updated `MultiSchemaField` to call `onChange` after setting the new option in state rather than before
- Updated the `CHANGELOG.md` accordingly
* - In order to avoid regressions, added a new `mergeDefaultsWithFormData` prop to the `Experimental_DefaultFormStateBehavior`
- Updated `mergeDefaultsWithFormData()` to add new optional `defaultSupercedesUndefined` that when true uses the defaults rather than `undefined` formData
- Updated `getDefaultFormState()` to pass true to `mergeDefaultsWithFormData` for `defaultSupercedesUndefined` when `mergeDefaultsIntoFormData` has the value `useDefaultIfFormDataUndefined`
- Updated the documentation for the new capabilities
- Updated the playground to add controls for the new `mergeDefaultsIntoFormData` option
- moved the `Show Error List` component over one column, making it inline radio buttons rather than a select
* - Improved documentation a teeny bit
* - More doc improvements
* - Responded to reviewer feedback
* - Fixed broken links
* - Added section header for wrapping BaseInputTemplate
* - Updated CHANGELOG.md
Copy file name to clipboardExpand all lines: CHANGELOG.md
+17-1
Original file line number
Diff line number
Diff line change
@@ -18,10 +18,26 @@ should change the heading of the (upcoming) version to include a major version b
18
18
19
19
# 5.22.0
20
20
21
+
## @rjsf/core
22
+
23
+
- Updated `MultiSchemaField` to call the `onChange` handler after setting the new option, fixing [#3997](https://github.com/rjsf-team/react-jsonschema-form/issues/3977) and [#4314](https://github.com/rjsf-team/react-jsonschema-form/issues/4314)
24
+
21
25
## @rjsf/utils
22
26
27
+
- Added `experimental_customMergeAllOf` option to `retrieveSchema()` and `getDefaultFormState()` to allow custom merging of `allOf` schemas
23
28
- Made fields with const property pre-filled and readonly, fixing [#2600](https://github.com/rjsf-team/react-jsonschema-form/issues/2600)
24
-
- Added `experimental_customMergeAllOf` option to `retrieveSchema` to allow custom merging of `allOf` schemas
29
+
- Added `mergeDefaultsIntoFormData` option to `Experimental_DefaultFormStateBehavior` type to control how to handle merging of defaults
30
+
- Updated `mergeDefaultsWithFormData()` to add new optional `defaultSupercedesUndefined` that when true uses the defaults rather than `undefined` formData, fixing [#4322](https://github.com/rjsf-team/react-jsonschema-form/issues/4322)
31
+
- Updated `getDefaultFormState()` to pass true to `mergeDefaultsWithFormData` for `defaultSupercedesUndefined` when `mergeDefaultsIntoFormData` has the value `useDefaultIfFormDataUndefined`, fixing [#4322](https://github.com/rjsf-team/react-jsonschema-form/issues/4322)
32
+
- Updated `getClosestMatchingOption()` to improve the scoring of sub-property objects that are provided over ones that aren't, fixing [#3997](https://github.com/rjsf-team/react-jsonschema-form/issues/3977) and [#4314](https://github.com/rjsf-team/react-jsonschema-form/issues/4314)
33
+
34
+
## Dev / docs / playground
35
+
36
+
- Updated the `form-props.md` to add documentation for the new `experimental_customMergeAllOf` props and the `experimental_defaultFormStateBehavior.mergeDefaultsIntoFormData` option
37
+
- Updated the `utility-functions.md` to add documentation for the new optional `defaultSupercedesUndefined` parameter and the two missing optional fields on `getDefaultFormState()`
38
+
- Updated the `custom-templates.md` to add a section header for wrapping `BaseInputTemplate`
39
+
- Updated the playground to add controls for the new `mergeDefaultsIntoFormData` option
40
+
- In the process, moved the `Show Error List` component over one column, making it inline radio buttons rather than a select
Copy file name to clipboardExpand all lines: packages/docs/docs/api-reference/form-props.md
+11
Original file line number
Diff line number
Diff line change
@@ -251,6 +251,17 @@ render(
251
251
);
252
252
```
253
253
254
+
### mergeDefaultsIntoFormData
255
+
256
+
Optional enumerated flag controlling how the defaults are merged into the form data when dealing with undefined values, defaulting to `useFormDataIfPresent`.
257
+
258
+
NOTE: If there is a default for a field and the `formData` is unspecified, the default ALWAYS merges.
|`useFormDataIfPresent`| Legacy behavior - Do not merge defaults if there is a value for a field in `formData` even if that value is explicitly set to `undefined`|
263
+
|`useDefaultIfFormDataUndefined`| If the value of a field within the `formData` is `undefined`, then use the default value instead |
264
+
254
265
## experimental_customMergeAllOf
255
266
256
267
The `experimental_customMergeAllOf` function allows you to provide a custom implementation for merging `allOf` schemas. This can be particularly useful in scenarios where the default [json-schema-merge-allof](https://github.com/mokkabonna/json-schema-merge-allof) library becomes a performance bottleneck, especially with large and complex schemas or doesn't satisfy your needs.
Copy file name to clipboardExpand all lines: packages/docs/docs/api-reference/utility-functions.md
+3
Original file line number
Diff line number
Diff line change
@@ -575,6 +575,7 @@ When merging defaults and form data, we want to merge in this specific way:
575
575
-[defaults]: T | undefined - The defaults to merge
576
576
-[formData]: T | undefined - The form data into which the defaults will be merged
577
577
-[mergeExtraArrayDefaults=false]: boolean - If true, any additional default array entries are appended onto the formData
578
+
-[defaultSupercedesUndefined=false]: boolean - If true, an explicit undefined value will be overwritten by the default value
578
579
579
580
#### Returns
580
581
@@ -897,6 +898,8 @@ Returns the superset of `formData` that includes the given set updated to includ
897
898
-[formData]: T | undefined - The current formData, if any, onto which to provide any missing defaults
898
899
-[rootSchema]: S | undefined - The root schema, used to primarily to look up `$ref`s
899
900
-[includeUndefinedValues=false]: boolean | "excludeObjectChildren" - Optional flag, if true, cause undefined values to be added as defaults. If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as false when computing defaults for any nested object properties.
901
+
-[experimental_defaultFormStateBehavior]: Experimental_DefaultFormStateBehavior - See `Form` documentation for the [experimental_defaultFormStateBehavior](./form-props.md#experimental_defaultFormStateBehavior) prop
902
+
-[experimental_customMergeAllOf]: Experimental_CustomMergeAllOf<S> - See `Form` documentation for the [experimental_customMergeAllOf](./form-props.md#experimental_customMergeAllOf) prop
0 commit comments