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
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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+13-2Lines changed: 13 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,17 +20,28 @@ should change the heading of the (upcoming) version to include a major version b
20
20
## @rjsf/core
21
21
22
22
- Added `initialDefaultsGenerated` flag to state, which indicates whether the initial generation of defaults has been completed
23
-
- Added `ObjectField` tests for additionalProperties with defaults
23
+
- Added `ObjectField` tests for additionalProperties with defaults
24
+
- Updated `Form` as follows to fix [#4796](https://github.com/rjsf-team/react-jsonschema-form/issues/4796)
25
+
- Refactored the `liveValidate()` and `mergeErrors()` functions out of `getStateFromProp()` and `processPendingChange()`
26
+
- Added new, optional `customErrors?: ErrorSchemaBuilder<T>` to the `FormState`, updating the `IChangeEvent` interface to remove all of the private variables
27
+
- 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
28
+
- This rework resulted in any custom errors passed from custom widgets/fields will now be remembered during the validation stage
29
+
- Removed the now unused `getPreviousCustomValidateErrors()` and `filterErrorsBasedOnSchema()` methods
30
+
- 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)
31
+
- Updated `NullField` to pass `fieldPathId.path` for the `onChange()` instead of `[name]`
24
32
25
33
## @rjsf/utils
26
34
27
35
- Updated `getDefaultFormState` to add a new `initialDefaultsGenerated` prop flag, along with type definitions, fixing uneditable & permanent defaults with additional properties [3759](https://github.com/rjsf-team/react-jsonschema-form/issues/3759)
28
36
- Updated `createSchemaUtils` definition to reflect addition of `initialDefaultsGenerated`
29
37
- Updated existing tests where `getDefaultFormState` is used to reflect addition of `initialDefaultsGenerated`
38
+
- Updated `validationDataMerge()` to add an additional, optional parameter `preventDuplicates = false`, that causes the `mergeObjects()` call to receive `preventDuplicates` instead of `true`
30
39
31
-
## @rjsf/docs
40
+
## Dev / docs / playground
32
41
33
42
- Updated docs for `getDefaultFormState` to reflect addition of `initialDefaultsGenerated` prop
43
+
- Updated `utility-functions.md` to update the `validationDataMerge()` function's new parameter
44
+
- Updated `custom-widgets-fields.md` to change the documentation around passing errors via `onChange()` to reflect the new reality
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