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
Adding feature to support const as default bug fix seeming like a regression (#4381)
Fixes#4344, #4361 and #4377
- In `@rjsf/utils`:
- Updated the `Experimental_DefaultFormStateBehavior` type to add new optional `constAsDefaults` prop with three choices
- Updated `getDefaultFormState()` to respond to the new `constAsDefaults` feature to limit `const` as defaults based on the `never` or `skipOneOf` choices
- Added tests for `getDefaultFormState()` to verify the new feature
- In `@rjsf/core`:
- Updated `SchemaField` to remove making the field readonly when const
- In `playground`:
- Updated `Header` to add support for `constAsDefaults`
- Updated the `CHANGELOG.md` accordingly
Copy file name to clipboardExpand all lines: CHANGELOG.md
+15
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,21 @@ should change the heading of the (upcoming) version to include a major version b
16
16
17
17
-->
18
18
19
+
# 5.23.0
20
+
21
+
## @rjsf/core
22
+
23
+
- Updated `SchemaField` to no longer make schema fields with const read-only by default, partially fixing [#4344](https://github.com/rjsf-team/react-jsonschema-form/issues/4344)
24
+
25
+
## @rjsf/utils
26
+
27
+
- Updated `Experimental_DefaultFormStateBehavior` to add a new `constAsDefaults` option
28
+
- Updated `getDefaultFormState()` to use the new `constAsDefaults` option to control how const is used for defaulting, fixing [#4344](https://github.com/rjsf-team/react-jsonschema-form/issues/4344), [#4361](https://github.com/rjsf-team/react-jsonschema-form/issues/4361) and [#4377](https://github.com/rjsf-team/react-jsonschema-form/issues/4377)
29
+
30
+
## Dev / docs / playground
31
+
32
+
- Updated the playground to add a selector for the `constAsDefaults` option
Copy file name to clipboardExpand all lines: packages/docs/docs/api-reference/form-props.md
+12
Original file line number
Diff line number
Diff line change
@@ -251,6 +251,18 @@ render(
251
251
);
252
252
```
253
253
254
+
### constAsDefaults
255
+
256
+
Optional enumerated flag controlling how const values are merged into the form data as defaults when dealing with undefined values, defaulting to `always`.
257
+
The defaulting behavior for this flag will always be controlled by the `emptyObjectField` flag value.
258
+
For instance, if `populateRequiredDefaults` is set and the const value is not required, it will not be set.
|`always`| A const value will always be merged into the form as a default. If there is are const values in a `oneOf` (for instance to create an enumeration with title different from the values), the first const value will be defaulted |
263
+
|`skipOneOf`| If const is in a `oneOf` it will NOT pick the first value as a default |
264
+
|`never`| A const value will never be used as a default |
265
+
254
266
### mergeDefaultsIntoFormData
255
267
256
268
Optional enumerated flag controlling how the defaults are merged into the form data when dealing with undefined values, defaulting to `useFormDataIfPresent`.
0 commit comments