@rjsf/core 5.12.1 → 5.13.1

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/index.js CHANGED
@@ -123,8 +123,20 @@ var ArrayField = class extends import_react.Component {
123
123
  if (event) {
124
124
  event.preventDefault();
125
125
  }
126
- const { onChange } = this.props;
126
+ const { onChange, errorSchema } = this.props;
127
127
  const { keyedFormData } = this.state;
128
+ let newErrorSchema;
129
+ if (errorSchema) {
130
+ newErrorSchema = {};
131
+ for (const idx in errorSchema) {
132
+ const i = parseInt(idx);
133
+ if (i <= index) {
134
+ (0, import_set.default)(newErrorSchema, [i], errorSchema[idx]);
135
+ } else if (i > index) {
136
+ (0, import_set.default)(newErrorSchema, [i + 1], errorSchema[idx]);
137
+ }
138
+ }
139
+ }
128
140
  const newKeyedFormDataRow = {
129
141
  key: generateRowId(),
130
142
  item: (0, import_cloneDeep.default)(keyedFormData[index].item)
@@ -140,7 +152,7 @@ var ArrayField = class extends import_react.Component {
140
152
  keyedFormData: newKeyedFormData,
141
153
  updatedKeyedFormData: true
142
154
  },
143
- () => onChange(keyedToPlainFormData(newKeyedFormData))
155
+ () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema)
144
156
  );
145
157
  };
146
158
  };
@@ -336,8 +348,20 @@ var ArrayField = class extends import_react.Component {
336
348
  if (event) {
337
349
  event.preventDefault();
338
350
  }
339
- const { onChange } = this.props;
351
+ const { onChange, errorSchema } = this.props;
340
352
  const { keyedFormData } = this.state;
353
+ let newErrorSchema;
354
+ if (errorSchema) {
355
+ newErrorSchema = {};
356
+ for (const idx in errorSchema) {
357
+ const i = parseInt(idx);
358
+ if (index === void 0 || i < index) {
359
+ (0, import_set.default)(newErrorSchema, [i], errorSchema[idx]);
360
+ } else if (i >= index) {
361
+ (0, import_set.default)(newErrorSchema, [i + 1], errorSchema[idx]);
362
+ }
363
+ }
364
+ }
341
365
  const newKeyedFormDataRow = {
342
366
  key: generateRowId(),
343
367
  item: this._getNewFormDataRow()
@@ -353,7 +377,7 @@ var ArrayField = class extends import_react.Component {
353
377
  keyedFormData: newKeyedFormData,
354
378
  updatedKeyedFormData: true
355
379
  },
356
- () => onChange(keyedToPlainFormData(newKeyedFormData))
380
+ () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema)
357
381
  );
358
382
  }
359
383
  /** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
@@ -892,7 +916,6 @@ var import_react2 = require("react");
892
916
  var import_get2 = __toESM(require("lodash/get"));
893
917
  var import_isEmpty = __toESM(require("lodash/isEmpty"));
894
918
  var import_omit = __toESM(require("lodash/omit"));
895
- var import_unset = __toESM(require("lodash/unset"));
896
919
  var import_utils3 = require("@rjsf/utils");
897
920
  var import_jsx_runtime3 = require("react/jsx-runtime");
898
921
  var AnyOfField = class extends import_react2.Component {
@@ -1015,9 +1038,8 @@ var AnyOfField = class extends import_react2.Component {
1015
1038
  const option = selectedOption >= 0 ? retrievedOptions[selectedOption] || null : null;
1016
1039
  let optionSchema;
1017
1040
  if (option) {
1018
- const { oneOf, anyOf, properties, ...remaining } = schema;
1019
- (0, import_unset.default)(remaining, import_utils3.ADDITIONAL_PROPERTY_FLAG);
1020
- optionSchema = !(0, import_isEmpty.default)(remaining) ? (0, import_utils3.mergeSchemas)(remaining, option) : option;
1041
+ const { required } = schema;
1042
+ optionSchema = required ? (0, import_utils3.mergeSchemas)({ required }, option) : option;
1021
1043
  }
1022
1044
  const translateEnum = title ? import_utils3.TranslatableString.TitleOptionPrefix : import_utils3.TranslatableString.OptionPrefix;
1023
1045
  const translateParams = title ? [title] : [];
@@ -1096,7 +1118,7 @@ var import_get3 = __toESM(require("lodash/get"));
1096
1118
  var import_has = __toESM(require("lodash/has"));
1097
1119
  var import_isObject3 = __toESM(require("lodash/isObject"));
1098
1120
  var import_set2 = __toESM(require("lodash/set"));
1099
- var import_unset2 = __toESM(require("lodash/unset"));
1121
+ var import_unset = __toESM(require("lodash/unset"));
1100
1122
  var import_jsx_runtime5 = require("react/jsx-runtime");
1101
1123
  var ObjectField = class extends import_react4.Component {
1102
1124
  constructor() {
@@ -1142,7 +1164,7 @@ var ObjectField = class extends import_react4.Component {
1142
1164
  event.preventDefault();
1143
1165
  const { onChange, formData } = this.props;
1144
1166
  const copiedFormData = { ...formData };
1145
- (0, import_unset2.default)(copiedFormData, key);
1167
+ (0, import_unset.default)(copiedFormData, key);
1146
1168
  onChange(copiedFormData);
1147
1169
  };
1148
1170
  };
@@ -3561,13 +3583,14 @@ var Form = class extends import_react17.Component {
3561
3583
  */
3562
3584
  validateForm() {
3563
3585
  const { extraErrors, extraErrorsBlockSubmit, focusOnFirstError, onError } = this.props;
3564
- const { formData } = this.state;
3586
+ const { formData, errors: prevErrors } = this.state;
3565
3587
  const schemaValidation = this.validate(formData);
3566
3588
  let errors = schemaValidation.errors;
3567
3589
  let errorSchema = schemaValidation.errorSchema;
3568
3590
  const schemaValidationErrors = errors;
3569
3591
  const schemaValidationErrorSchema = errorSchema;
3570
- if (errors.length > 0 || extraErrors && extraErrorsBlockSubmit) {
3592
+ const hasError = errors.length > 0 || extraErrors && extraErrorsBlockSubmit;
3593
+ if (hasError) {
3571
3594
  if (extraErrors) {
3572
3595
  const merged = (0, import_utils39.validationDataMerge)(schemaValidation, extraErrors);
3573
3596
  errorSchema = merged.errorSchema;
@@ -3595,9 +3618,15 @@ var Form = class extends import_react17.Component {
3595
3618
  }
3596
3619
  }
3597
3620
  );
3598
- return false;
3621
+ } else if (prevErrors.length > 0) {
3622
+ this.setState({
3623
+ errors: [],
3624
+ errorSchema: {},
3625
+ schemaValidationErrors: [],
3626
+ schemaValidationErrorSchema: {}
3627
+ });
3599
3628
  }
3600
- return true;
3629
+ return !hasError;
3601
3630
  }
3602
3631
  /** Renders the `Form` fields inside the <form> | `tagName` or `_internalFormWrapper`, rendering any errors if
3603
3632
  * needed along with the submit button or any children of the form.