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 4796 by simplifying Form onChange error processing (#4799)
* Fix 4796 by simplifying Form onChange error processing
Fixes#4796 by simplifying `Form.onChange` error processing and removing old code in `LayoutGridField`
- In `@rjsf/utils`
- Updated `validationDataMerge()` to add an additional, optional parameter `preventDuplicates = false`, that causes the `mergeObjects()` call to receive `preventDuplicates` instead of `true`
- In `@rjsf/core`, updated `Form` as follows to fix [#4796](#4796)
- Refactored the `liveValidate()` and `mergeErrors()` functions out of `getStateFromProp()` and `processPendingChange()`
- Added new, optional `customErrors?: ErrorSchemaBuilder<T>` to the `FormState`, updating the `IChangeEvent` interface to remove all of the private variables
- Reworked the `newErrorSchema` handling in `processPendingChange()` to simplify the handling since `newErrorSchema` is now path-specific, adding `newErrorSchema` to `customErrors` when they don't match an existing validator-based validation
- This rework resulted in any custom errors passed from custom widgets/fields will now be remembered during the validation stage
- Removed the now unused `getPreviousCustomValidateErrors()` and `filterErrorsBasedOnSchema()` methods
- Also, updated `LayoutGridField` to simplify `onFieldChange()` to just return the given `errorSchema` now that it is path-specific, fixing [#4796](#4796)
- Also, updated `NullField` to pass `fieldPathId.path` for the `onChange()` instead of `[name]`
- Updated the tests for `StringField`, `ArrayField` and `ObjectField` to verify all of the new error processing logic in `onChange()`
- Updated `utility-functions.md` to update the `validationDataMerge()` function's new parameter
- Updated `custom-widgets-fields.md` to change the documentation around passing errors via `onChange()` to reflect the new reality
- Updated the `CHANGELOG.md` accordingly
# Conflicts:
# CHANGELOG.md
* - Updated `v6.x upgrade guide.md` to document the changes mentioned above
* - Updated `CHANGELOG.md` to merge a few comments
* - More `CHANGELOG.md` changes
* Update packages/docs/docs/migration-guides/v6.x upgrade guide.md
Co-authored-by: Nick Grosenbacher <[email protected]>
---------
Co-authored-by: Nick Grosenbacher <[email protected]>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+12-2Lines changed: 12 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,14 @@ should change the heading of the (upcoming) version to include a major version b
37
37
- Updated `ArrayField` and `ObjectField` to check whether it `shouldRenderOptionalData()` and if true, calls `ObjectDataControlsField` and passes the result to its associated render template as `optionalDataControl`
38
38
- Updated `ArrayFieldTemplate`, `ObjectFieldTemplate`, `TitleField` to add support for the new `optionalDataControl` feature
39
39
- Added the new `OptionalDataControlTemplate` to the theme, adding it to the `templates` list
40
+
- Updated `Form` as follows to fix [#4796](https://github.com/rjsf-team/react-jsonschema-form/issues/4796)
41
+
- Refactored the `liveValidate()` and `mergeErrors()` functions out of `getStateFromProp()` and `processPendingChange()`
42
+
- Added new, optional `customErrors?: ErrorSchemaBuilder<T>` to the `FormState`, updating the `IChangeEvent` interface to remove all of the private variables
43
+
- Reworked the `newErrorSchema` handling in `processPendingChange()` to simplify the handling since `newErrorSchema` is now path-specific, adding `newErrorSchema` to `customErrors` when they don't match an existing validator-based validation
44
+
- This rework resulted in any custom errors passed from custom widgets/fields will now be remembered during the validation stage
45
+
- Removed the now unused `getPreviousCustomValidateErrors()` and `filterErrorsBasedOnSchema()` methods
46
+
- Updated `LayoutGridField` to simplify `onFieldChange()` to just return the given `errorSchema` now that it is path-specific, fixing [#4796](https://github.com/rjsf-team/react-jsonschema-form/issues/4796)
47
+
- Updated `NullField` to pass `fieldPathId.path` for the `onChange()` instead of `[name]`
40
48
41
49
## @rjsf/daisyui
42
50
@@ -99,16 +107,18 @@ should change the heading of the (upcoming) version to include a major version b
99
107
- Updated `getDefaultFormState` to fix an issue where optional array props had their default set to an empty array when they shouldn't be
100
108
- Updated the `TranslatableString` enum to add three new strings in support of the new feature: `OptionalObjectAdd`, `OptionalObjectRemove` and `OptionalObjectEmptyMsg`
101
109
- Added four new utility functions: `isFormDataAvailable()`, `isRootSchema()`, `optionalControlsId()`, and `shouldRenderOptionalField()`
110
+
- Updated `validationDataMerge()` to add an additional, optional parameter `preventDuplicates = false`, that causes the `mergeObjects()` call to receive `preventDuplicates` instead of `true`
102
111
103
112
## Dev / docs / playground
104
113
105
114
- Updated docs for `getDefaultFormState` to reflect addition of the `initialDefaultsGenerated` prop
106
-
- Updated `utility-function.me` docs to add documentation for the new functions
115
+
- Updated `utility-function.me` docs to add documentation for the new functions and to update the `validationDataMerge()` function's new parameter
107
116
- Also updated docs for `retrieveSchema` and `SchemaUtilsType` for the new prop
108
117
- Updated `uiSchema.md` to add documentation for the new `enableOptionalDataFieldForType` prop
109
-
- Updated the `v6x upgrade guide.md` to document the new feature and utility functions and changes to `retrieveSchema`
110
118
- Updated the playground to add a new `Optional Data Controls` example
111
119
- Updated the snapshot and jest tests for `Form` to test the new `Optional Data Controls` feature
120
+
- Updated `custom-widgets-fields.md` to change the documentation around passing errors via `onChange()` to reflect the new reality
121
+
- Updated the `v6x upgrade guide.md` to document the new feature, utility functions and changes to existing method parameters
Copy file name to clipboardExpand all lines: packages/docs/docs/advanced-customization/custom-widgets-fields.md
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,12 +100,11 @@ The default widgets you can override are:
100
100
## Raising errors from within a custom widget or field
101
101
102
102
You can raise custom 'live validation' errors by overriding the `onChange` method to provide feedback while users are actively changing the form data.
103
-
Note that these errors are temporary and are not recognized during the form validation process.
103
+
If you do set errors this way, you must also clear them this way by passing `undefined` to the `onChange()` for the `errorSchema` parameter.
104
104
105
105
:::warning
106
106
107
-
This method of raising errors _only_ runs during `onChange`, i.e. when the user is changing data. This will not catch errors `onSubmit`, i.e when submitting the form.
108
-
If you wish to add generic validation logic for your component, you should use the [`customValidate` Form prop](../api-reference/form-props.md#customvalidate).
107
+
While these errors are retained during validation, it is still preferred for you to use the [`customValidate` Form prop](../api-reference/form-props.md#customvalidate) mechanism instead.
0 commit comments