@rjsf/core 5.24.2 → 5.24.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.umd.js +31 -4
- package/dist/index.esm.js +34 -5
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +31 -4
- package/dist/index.js.map +2 -2
- package/lib/components/Form.d.ts +5 -0
- package/lib/components/Form.js +37 -5
- package/lib/components/Form.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -7
- package/src/components/Form.tsx +43 -4
package/dist/index.js
CHANGED
|
@@ -3709,6 +3709,21 @@ var Form = class extends import_react17.Component {
|
|
|
3709
3709
|
shouldComponentUpdate(nextProps, nextState) {
|
|
3710
3710
|
return (0, import_utils39.shouldRender)(this, nextProps, nextState);
|
|
3711
3711
|
}
|
|
3712
|
+
/** Gets the previously raised customValidate errors.
|
|
3713
|
+
*
|
|
3714
|
+
* @returns the previous customValidate errors
|
|
3715
|
+
*/
|
|
3716
|
+
getPreviousCustomValidateErrors() {
|
|
3717
|
+
const { customValidate, uiSchema } = this.props;
|
|
3718
|
+
const prevFormData = this.state.formData;
|
|
3719
|
+
let customValidateErrors = {};
|
|
3720
|
+
if (typeof customValidate === "function") {
|
|
3721
|
+
const errorHandler = customValidate(prevFormData, (0, import_utils39.createErrorHandler)(prevFormData), uiSchema);
|
|
3722
|
+
const userErrorSchema = (0, import_utils39.unwrapErrorHandler)(errorHandler);
|
|
3723
|
+
customValidateErrors = userErrorSchema;
|
|
3724
|
+
}
|
|
3725
|
+
return customValidateErrors;
|
|
3726
|
+
}
|
|
3712
3727
|
/** Validates the `formData` against the `schema` using the `altSchemaUtils` (if provided otherwise it uses the
|
|
3713
3728
|
* `schemaUtils` in the state), returning the results.
|
|
3714
3729
|
*
|
|
@@ -3753,17 +3768,29 @@ var Form = class extends import_react17.Component {
|
|
|
3753
3768
|
if (resolvedSchema?.type !== "object" && resolvedSchema?.type !== "array") {
|
|
3754
3769
|
filteredErrors.__errors = schemaErrors.__errors;
|
|
3755
3770
|
}
|
|
3756
|
-
const
|
|
3771
|
+
const prevCustomValidateErrors = this.getPreviousCustomValidateErrors();
|
|
3772
|
+
const filterPreviousCustomErrors = (errors = [], prevCustomErrors) => {
|
|
3773
|
+
if (errors.length === 0) {
|
|
3774
|
+
return errors;
|
|
3775
|
+
}
|
|
3776
|
+
return errors.filter((error) => {
|
|
3777
|
+
return !prevCustomErrors.includes(error);
|
|
3778
|
+
});
|
|
3779
|
+
};
|
|
3780
|
+
const filterNilOrEmptyErrors = (errors, previousCustomValidateErrors = {}) => {
|
|
3757
3781
|
(0, import_forEach.default)(errors, (errorAtKey, errorKey) => {
|
|
3758
|
-
|
|
3782
|
+
const prevCustomValidateErrorAtKey = previousCustomValidateErrors[errorKey];
|
|
3783
|
+
if ((0, import_isNil.default)(errorAtKey) || Array.isArray(errorAtKey) && errorAtKey.length === 0) {
|
|
3759
3784
|
delete errors[errorKey];
|
|
3785
|
+
} else if ((0, import_utils39.isObject)(errorAtKey) && (0, import_utils39.isObject)(prevCustomValidateErrorAtKey) && Array.isArray(prevCustomValidateErrorAtKey?.__errors)) {
|
|
3786
|
+
errors[errorKey] = filterPreviousCustomErrors(errorAtKey.__errors, prevCustomValidateErrorAtKey.__errors);
|
|
3760
3787
|
} else if (typeof errorAtKey === "object" && !Array.isArray(errorAtKey.__errors)) {
|
|
3761
|
-
filterNilOrEmptyErrors(errorAtKey);
|
|
3788
|
+
filterNilOrEmptyErrors(errorAtKey, previousCustomValidateErrors[errorKey]);
|
|
3762
3789
|
}
|
|
3763
3790
|
});
|
|
3764
3791
|
return errors;
|
|
3765
3792
|
};
|
|
3766
|
-
return filterNilOrEmptyErrors(filteredErrors);
|
|
3793
|
+
return filterNilOrEmptyErrors(filteredErrors, prevCustomValidateErrors);
|
|
3767
3794
|
}
|
|
3768
3795
|
/**
|
|
3769
3796
|
* If the retrievedSchema has changed the new retrievedSchema is returned.
|