@rjsf/core 5.24.3 → 5.24.5

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 CHANGED
@@ -3452,6 +3452,21 @@
3452
3452
  shouldComponentUpdate(nextProps, nextState) {
3453
3453
  return utils.shouldRender(this, nextProps, nextState);
3454
3454
  }
3455
+ /** Gets the previously raised customValidate errors.
3456
+ *
3457
+ * @returns the previous customValidate errors
3458
+ */
3459
+ getPreviousCustomValidateErrors() {
3460
+ const { customValidate, uiSchema } = this.props;
3461
+ const prevFormData = this.state.formData;
3462
+ let customValidateErrors = {};
3463
+ if (typeof customValidate === "function") {
3464
+ const errorHandler = customValidate(prevFormData, utils.createErrorHandler(prevFormData), uiSchema);
3465
+ const userErrorSchema = utils.unwrapErrorHandler(errorHandler);
3466
+ customValidateErrors = userErrorSchema;
3467
+ }
3468
+ return customValidateErrors;
3469
+ }
3455
3470
  /** Validates the `formData` against the `schema` using the `altSchemaUtils` (if provided otherwise it uses the
3456
3471
  * `schemaUtils` in the state), returning the results.
3457
3472
  *
@@ -3496,17 +3511,29 @@
3496
3511
  if (resolvedSchema?.type !== "object" && resolvedSchema?.type !== "array") {
3497
3512
  filteredErrors.__errors = schemaErrors.__errors;
3498
3513
  }
3499
- const filterNilOrEmptyErrors = (errors) => {
3514
+ const prevCustomValidateErrors = this.getPreviousCustomValidateErrors();
3515
+ const filterPreviousCustomErrors = (errors = [], prevCustomErrors) => {
3516
+ if (errors.length === 0) {
3517
+ return errors;
3518
+ }
3519
+ return errors.filter((error) => {
3520
+ return !prevCustomErrors.includes(error);
3521
+ });
3522
+ };
3523
+ const filterNilOrEmptyErrors = (errors, previousCustomValidateErrors = {}) => {
3500
3524
  _forEach(errors, (errorAtKey, errorKey) => {
3501
- if (_isNil(errorAtKey)) {
3525
+ const prevCustomValidateErrorAtKey = previousCustomValidateErrors[errorKey];
3526
+ if (_isNil(errorAtKey) || Array.isArray(errorAtKey) && errorAtKey.length === 0) {
3502
3527
  delete errors[errorKey];
3528
+ } else if (utils.isObject(errorAtKey) && utils.isObject(prevCustomValidateErrorAtKey) && Array.isArray(prevCustomValidateErrorAtKey?.__errors)) {
3529
+ errors[errorKey] = filterPreviousCustomErrors(errorAtKey.__errors, prevCustomValidateErrorAtKey.__errors);
3503
3530
  } else if (typeof errorAtKey === "object" && !Array.isArray(errorAtKey.__errors)) {
3504
- filterNilOrEmptyErrors(errorAtKey);
3531
+ filterNilOrEmptyErrors(errorAtKey, previousCustomValidateErrors[errorKey]);
3505
3532
  }
3506
3533
  });
3507
3534
  return errors;
3508
3535
  };
3509
- return filterNilOrEmptyErrors(filteredErrors);
3536
+ return filterNilOrEmptyErrors(filteredErrors, prevCustomValidateErrors);
3510
3537
  }
3511
3538
  /**
3512
3539
  * If the retrievedSchema has changed the new retrievedSchema is returned.
package/dist/index.esm.js CHANGED
@@ -15,7 +15,9 @@ import {
15
15
  toErrorList,
16
16
  UI_GLOBAL_OPTIONS_KEY,
17
17
  UI_OPTIONS_KEY as UI_OPTIONS_KEY2,
18
- validationDataMerge
18
+ validationDataMerge,
19
+ createErrorHandler,
20
+ unwrapErrorHandler
19
21
  } from "@rjsf/utils";
20
22
  import _forEach from "lodash/forEach";
21
23
  import _get from "lodash/get";
@@ -3804,6 +3806,21 @@ var Form = class extends Component5 {
3804
3806
  shouldComponentUpdate(nextProps, nextState) {
3805
3807
  return shouldRender(this, nextProps, nextState);
3806
3808
  }
3809
+ /** Gets the previously raised customValidate errors.
3810
+ *
3811
+ * @returns the previous customValidate errors
3812
+ */
3813
+ getPreviousCustomValidateErrors() {
3814
+ const { customValidate, uiSchema } = this.props;
3815
+ const prevFormData = this.state.formData;
3816
+ let customValidateErrors = {};
3817
+ if (typeof customValidate === "function") {
3818
+ const errorHandler = customValidate(prevFormData, createErrorHandler(prevFormData), uiSchema);
3819
+ const userErrorSchema = unwrapErrorHandler(errorHandler);
3820
+ customValidateErrors = userErrorSchema;
3821
+ }
3822
+ return customValidateErrors;
3823
+ }
3807
3824
  /** Validates the `formData` against the `schema` using the `altSchemaUtils` (if provided otherwise it uses the
3808
3825
  * `schemaUtils` in the state), returning the results.
3809
3826
  *
@@ -3848,17 +3865,29 @@ var Form = class extends Component5 {
3848
3865
  if (resolvedSchema?.type !== "object" && resolvedSchema?.type !== "array") {
3849
3866
  filteredErrors.__errors = schemaErrors.__errors;
3850
3867
  }
3851
- const filterNilOrEmptyErrors = (errors) => {
3868
+ const prevCustomValidateErrors = this.getPreviousCustomValidateErrors();
3869
+ const filterPreviousCustomErrors = (errors = [], prevCustomErrors) => {
3870
+ if (errors.length === 0) {
3871
+ return errors;
3872
+ }
3873
+ return errors.filter((error) => {
3874
+ return !prevCustomErrors.includes(error);
3875
+ });
3876
+ };
3877
+ const filterNilOrEmptyErrors = (errors, previousCustomValidateErrors = {}) => {
3852
3878
  _forEach(errors, (errorAtKey, errorKey) => {
3853
- if (_isNil(errorAtKey)) {
3879
+ const prevCustomValidateErrorAtKey = previousCustomValidateErrors[errorKey];
3880
+ if (_isNil(errorAtKey) || Array.isArray(errorAtKey) && errorAtKey.length === 0) {
3854
3881
  delete errors[errorKey];
3882
+ } else if (isObject5(errorAtKey) && isObject5(prevCustomValidateErrorAtKey) && Array.isArray(prevCustomValidateErrorAtKey?.__errors)) {
3883
+ errors[errorKey] = filterPreviousCustomErrors(errorAtKey.__errors, prevCustomValidateErrorAtKey.__errors);
3855
3884
  } else if (typeof errorAtKey === "object" && !Array.isArray(errorAtKey.__errors)) {
3856
- filterNilOrEmptyErrors(errorAtKey);
3885
+ filterNilOrEmptyErrors(errorAtKey, previousCustomValidateErrors[errorKey]);
3857
3886
  }
3858
3887
  });
3859
3888
  return errors;
3860
3889
  };
3861
- return filterNilOrEmptyErrors(filteredErrors);
3890
+ return filterNilOrEmptyErrors(filteredErrors, prevCustomValidateErrors);
3862
3891
  }
3863
3892
  /**
3864
3893
  * If the retrievedSchema has changed the new retrievedSchema is returned.