@rjsf/core 5.0.0-beta.8 → 5.0.0-beta.9

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.
@@ -784,9 +784,11 @@ class ArrayField extends React.Component {
784
784
  } = this.props;
785
785
  const {
786
786
  fields: {
787
- ArraySchemaField
787
+ ArraySchemaField,
788
+ SchemaField
788
789
  }
789
790
  } = registry;
791
+ const ItemSchemaField = ArraySchemaField || SchemaField;
790
792
  const {
791
793
  orderable = true,
792
794
  removable = true
@@ -799,7 +801,7 @@ class ArrayField extends React.Component {
799
801
  };
800
802
  has.toolbar = Object.keys(has).some(key => has[key]);
801
803
  return {
802
- children: /*#__PURE__*/React__default["default"].createElement(ArraySchemaField, {
804
+ children: /*#__PURE__*/React__default["default"].createElement(ItemSchemaField, {
803
805
  name: name,
804
806
  index: index,
805
807
  schema: itemSchema,
@@ -833,7 +835,8 @@ class ArrayField extends React.Component {
833
835
  onDropIndexClick: this.onDropIndexClick,
834
836
  onReorderClick: this.onReorderClick,
835
837
  readonly,
836
- registry
838
+ registry,
839
+ uiSchema: itemUiSchema
837
840
  };
838
841
  }
839
842
 
@@ -1892,7 +1895,7 @@ function NullField(props) {
1892
1895
  const fields = {
1893
1896
  AnyOfField: AnyOfField,
1894
1897
  ArrayField,
1895
- ArraySchemaField: SchemaField,
1898
+ // ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
1896
1899
  BooleanField,
1897
1900
  NumberField,
1898
1901
  ObjectField,
@@ -1948,7 +1951,8 @@ function ArrayFieldItemTemplate(props) {
1948
1951
  onDropIndexClick,
1949
1952
  onReorderClick,
1950
1953
  readonly,
1951
- registry
1954
+ registry,
1955
+ uiSchema
1952
1956
  } = props;
1953
1957
  const {
1954
1958
  MoveDownButton,
@@ -1976,15 +1980,18 @@ function ArrayFieldItemTemplate(props) {
1976
1980
  }, (hasMoveUp || hasMoveDown) && /*#__PURE__*/React__default["default"].createElement(MoveUpButton, {
1977
1981
  style: btnStyle,
1978
1982
  disabled: disabled || readonly || !hasMoveUp,
1979
- onClick: onReorderClick(index, index - 1)
1983
+ onClick: onReorderClick(index, index - 1),
1984
+ uiSchema: uiSchema
1980
1985
  }), (hasMoveUp || hasMoveDown) && /*#__PURE__*/React__default["default"].createElement(MoveDownButton, {
1981
1986
  style: btnStyle,
1982
1987
  disabled: disabled || readonly || !hasMoveDown,
1983
- onClick: onReorderClick(index, index + 1)
1988
+ onClick: onReorderClick(index, index + 1),
1989
+ uiSchema: uiSchema
1984
1990
  }), hasRemove && /*#__PURE__*/React__default["default"].createElement(RemoveButton, {
1985
1991
  style: btnStyle,
1986
1992
  disabled: disabled || readonly,
1987
- onClick: onDropIndexClick(index)
1993
+ onClick: onDropIndexClick(index),
1994
+ uiSchema: uiSchema
1988
1995
  }))));
1989
1996
  }
1990
1997
 
@@ -2046,7 +2053,8 @@ function ArrayFieldTemplate(props) {
2046
2053
  })), canAdd && /*#__PURE__*/React__default["default"].createElement(AddButton, {
2047
2054
  className: "array-item-add",
2048
2055
  onClick: onAddClick,
2049
- disabled: disabled || readonly
2056
+ disabled: disabled || readonly,
2057
+ uiSchema: uiSchema
2050
2058
  }));
2051
2059
  }
2052
2060
 
@@ -2203,6 +2211,7 @@ function IconButton(props) {
2203
2211
  iconType = "default",
2204
2212
  icon,
2205
2213
  className,
2214
+ uiSchema,
2206
2215
  ...otherProps
2207
2216
  } = props;
2208
2217
  return /*#__PURE__*/React__default["default"].createElement("button", {
@@ -2366,6 +2375,7 @@ function WrapIfAdditional(props) {
2366
2375
  required,
2367
2376
  schema,
2368
2377
  children,
2378
+ uiSchema,
2369
2379
  registry
2370
2380
  } = props;
2371
2381
  const {
@@ -2409,7 +2419,8 @@ function WrapIfAdditional(props) {
2409
2419
  border: "0"
2410
2420
  },
2411
2421
  disabled: disabled || readonly,
2412
- onClick: onDropPropertyClick(label)
2422
+ onClick: onDropPropertyClick(label),
2423
+ uiSchema: uiSchema
2413
2424
  }))));
2414
2425
  }
2415
2426
 
@@ -2549,7 +2560,8 @@ function ObjectFieldTemplate(props) {
2549
2560
  }), properties.map(prop => prop.content), utils.canExpand(schema, uiSchema, formData) && /*#__PURE__*/React__default["default"].createElement(AddButton, {
2550
2561
  className: "object-property-expand",
2551
2562
  onClick: onAddClick(schema),
2552
- disabled: disabled || readonly
2563
+ disabled: disabled || readonly,
2564
+ uiSchema: uiSchema
2553
2565
  }));
2554
2566
  }
2555
2567
 
@@ -3665,8 +3677,7 @@ class Form extends React.Component {
3665
3677
  omitExtraData,
3666
3678
  extraErrors,
3667
3679
  noValidate,
3668
- onSubmit,
3669
- onError
3680
+ onSubmit
3670
3681
  } = this.props;
3671
3682
  let {
3672
3683
  formData: newFormData
@@ -3683,54 +3694,26 @@ class Form extends React.Component {
3683
3694
  newFormData = this.getUsedFormData(newFormData, fieldNames);
3684
3695
  }
3685
3696
 
3686
- if (!noValidate) {
3687
- const schemaValidation = this.validate(schemaUtils, newFormData);
3688
- let errors = schemaValidation.errors;
3689
- let errorSchema = schemaValidation.errorSchema;
3690
- const schemaValidationErrors = errors;
3691
- const schemaValidationErrorSchema = errorSchema;
3692
-
3693
- if (errors.length > 0) {
3694
- if (extraErrors) {
3695
- const merged = schemaUtils.mergeValidationData(schemaValidation, extraErrors);
3696
- errorSchema = merged.errorSchema;
3697
- errors = merged.errors;
3697
+ if (noValidate || this.validateForm()) {
3698
+ // There are no errors generated through schema validation.
3699
+ // Check for user provided errors and update state accordingly.
3700
+ const errorSchema = extraErrors || {};
3701
+ const errors = extraErrors ? schemaUtils.getValidator().toErrorList(extraErrors) : [];
3702
+ this.setState({
3703
+ formData: newFormData,
3704
+ errors,
3705
+ errorSchema,
3706
+ schemaValidationErrors: [],
3707
+ schemaValidationErrorSchema: {}
3708
+ }, () => {
3709
+ if (onSubmit) {
3710
+ onSubmit({ ...this.state,
3711
+ formData: newFormData,
3712
+ status: "submitted"
3713
+ }, event);
3698
3714
  }
3699
-
3700
- this.setState({
3701
- errors,
3702
- errorSchema,
3703
- schemaValidationErrors,
3704
- schemaValidationErrorSchema
3705
- }, () => {
3706
- if (onError) {
3707
- onError(errors);
3708
- } else {
3709
- console.error("Form validation failed", errors);
3710
- }
3711
- });
3712
- return;
3713
- }
3714
- } // There are no errors generated through schema validation.
3715
- // Check for user provided errors and update state accordingly.
3716
-
3717
-
3718
- const errorSchema = extraErrors || {};
3719
- const errors = extraErrors ? schemaUtils.getValidator().toErrorList(extraErrors) : [];
3720
- this.setState({
3721
- formData: newFormData,
3722
- errors,
3723
- errorSchema,
3724
- schemaValidationErrors: [],
3725
- schemaValidationErrorSchema: {}
3726
- }, () => {
3727
- if (onSubmit) {
3728
- onSubmit({ ...this.state,
3729
- formData: newFormData,
3730
- status: "submitted"
3731
- }, event);
3732
- }
3733
- });
3715
+ });
3716
+ }
3734
3717
  };
3735
3718
 
3736
3719
  if (!props.validator) {
@@ -3958,6 +3941,54 @@ class Form extends React.Component {
3958
3941
  this.formElement.current.requestSubmit();
3959
3942
  }
3960
3943
  }
3944
+ /** Programmatically validate the form. If `onError` is provided, then it will be called with the list of errors the
3945
+ * same way as would happen on form submission.
3946
+ *
3947
+ * @returns - True if the form is valid, false otherwise.
3948
+ */
3949
+
3950
+
3951
+ validateForm() {
3952
+ const {
3953
+ extraErrors,
3954
+ onError
3955
+ } = this.props;
3956
+ const {
3957
+ formData
3958
+ } = this.state;
3959
+ const {
3960
+ schemaUtils
3961
+ } = this.state;
3962
+ const schemaValidation = this.validate(schemaUtils, formData);
3963
+ let errors = schemaValidation.errors;
3964
+ let errorSchema = schemaValidation.errorSchema;
3965
+ const schemaValidationErrors = errors;
3966
+ const schemaValidationErrorSchema = errorSchema;
3967
+
3968
+ if (errors.length > 0) {
3969
+ if (extraErrors) {
3970
+ const merged = schemaUtils.mergeValidationData(schemaValidation, extraErrors);
3971
+ errorSchema = merged.errorSchema;
3972
+ errors = merged.errors;
3973
+ }
3974
+
3975
+ this.setState({
3976
+ errors,
3977
+ errorSchema,
3978
+ schemaValidationErrors,
3979
+ schemaValidationErrorSchema
3980
+ }, () => {
3981
+ if (onError) {
3982
+ onError(errors);
3983
+ } else {
3984
+ console.error("Form validation failed", errors);
3985
+ }
3986
+ });
3987
+ return false;
3988
+ }
3989
+
3990
+ return true;
3991
+ }
3961
3992
  /** Renders the `Form` fields inside the <form> | `tagName` or `_internalFormWrapper`, rendering any errors if
3962
3993
  * needed along with the submit button or any children of the form.
3963
3994
  */