@rjsf/core 5.0.0-beta.10 → 5.0.0-beta.11

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.
@@ -229,7 +229,7 @@ class ArrayField extends React.Component {
229
229
  };
230
230
 
231
231
  this.onChangeForIndex = index => {
232
- return (value, newErrorSchema) => {
232
+ return (value, newErrorSchema, id) => {
233
233
  const {
234
234
  formData,
235
235
  onChange,
@@ -244,15 +244,16 @@ class ArrayField extends React.Component {
244
244
  });
245
245
  onChange(newFormData, errorSchema && errorSchema && { ...errorSchema,
246
246
  [index]: newErrorSchema
247
- });
247
+ }, id);
248
248
  };
249
249
  };
250
250
 
251
251
  this.onSelectChange = value => {
252
252
  const {
253
- onChange
253
+ onChange,
254
+ idSchema
254
255
  } = this.props;
255
- onChange(value);
256
+ onChange(value, undefined, idSchema && idSchema.$id);
256
257
  };
257
258
 
258
259
  const {
@@ -897,19 +898,19 @@ function BooleanField(props) {
897
898
 
898
899
  // We deprecated enumNames in v5. It's intentionally omitted from RSJFSchema type, so we need to cast here.
899
900
  const schemaWithEnumNames = schema;
900
- schema.enum = (_schema$enum = schema.enum) != null ? _schema$enum : [true, false];
901
+ const enums = (_schema$enum = schema.enum) != null ? _schema$enum : [true, false];
901
902
 
902
- if (!schemaWithEnumNames.enumNames && schema.enum && schema.enum.length === 2 && schema.enum.every(v => typeof v === "boolean")) {
903
+ if (!schemaWithEnumNames.enumNames && enums.length === 2 && enums.every(v => typeof v === "boolean")) {
903
904
  enumOptions = [{
904
- value: schema.enum[0],
905
- label: schema.enum[0] ? "Yes" : "No"
905
+ value: enums[0],
906
+ label: enums[0] ? "Yes" : "No"
906
907
  }, {
907
- value: schema.enum[1],
908
- label: schema.enum[1] ? "Yes" : "No"
908
+ value: enums[1],
909
+ label: enums[1] ? "Yes" : "No"
909
910
  }];
910
911
  } else {
911
912
  enumOptions = utils.optionsList({
912
- enum: schema.enum,
913
+ enum: enums,
913
914
  // NOTE: enumNames is deprecated, but still supported for now.
914
915
  enumNames: schemaWithEnumNames.enumNames
915
916
  });
@@ -985,7 +986,7 @@ class AnyOfField extends React.Component {
985
986
  } // Call getDefaultFormState to make sure defaults are populated on change.
986
987
 
987
988
 
988
- onChange(schemaUtils.getDefaultFormState(options[selectedOption], newFormData));
989
+ onChange(schemaUtils.getDefaultFormState(options[selectedOption], newFormData), undefined, this.getFieldId());
989
990
  this.setState({
990
991
  selectedOption: parseInt(option, 10)
991
992
  });
@@ -1059,8 +1060,17 @@ class AnyOfField extends React.Component {
1059
1060
  */
1060
1061
 
1061
1062
 
1063
+ getFieldId() {
1064
+ const {
1065
+ idSchema,
1066
+ schema
1067
+ } = this.props;
1068
+ return "" + idSchema.$id + (schema.oneOf ? "__oneof_select" : "__anyof_select");
1069
+ }
1062
1070
  /** Renders the `AnyOfField` selector along with a `SchemaField` for the value of the `formData`
1063
1071
  */
1072
+
1073
+
1064
1074
  render() {
1065
1075
  const {
1066
1076
  name,
@@ -1079,8 +1089,7 @@ class AnyOfField extends React.Component {
1079
1089
  onFocus,
1080
1090
  options,
1081
1091
  registry,
1082
- uiSchema,
1083
- schema
1092
+ uiSchema
1084
1093
  } = this.props;
1085
1094
  const {
1086
1095
  widgets,
@@ -1119,7 +1128,7 @@ class AnyOfField extends React.Component {
1119
1128
  }, /*#__PURE__*/React__default["default"].createElement("div", {
1120
1129
  className: "form-group"
1121
1130
  }, /*#__PURE__*/React__default["default"].createElement(Widget, {
1122
- id: "" + idSchema.$id + (schema.oneOf ? "__oneof_select" : "__anyof_select"),
1131
+ id: this.getFieldId(),
1123
1132
  schema: {
1124
1133
  type: "number",
1125
1134
  default: 0
@@ -1258,7 +1267,7 @@ class ObjectField extends React.Component {
1258
1267
  addedByAdditionalProperties = false;
1259
1268
  }
1260
1269
 
1261
- return (value, newErrorSchema) => {
1270
+ return (value, newErrorSchema, id) => {
1262
1271
  const {
1263
1272
  formData,
1264
1273
  onChange,
@@ -1281,7 +1290,7 @@ class ObjectField extends React.Component {
1281
1290
  };
1282
1291
  onChange(newFormData, errorSchema && errorSchema && { ...errorSchema,
1283
1292
  [name]: newErrorSchema
1284
- });
1293
+ }, id);
1285
1294
  };
1286
1295
  };
1287
1296
 
@@ -1350,7 +1359,7 @@ class ObjectField extends React.Component {
1350
1359
  };
1351
1360
 
1352
1361
  this.handleAddClick = schema => () => {
1353
- if (!isObject__default["default"](schema.additionalProperties)) {
1362
+ if (!schema.additionalProperties) {
1354
1363
  return;
1355
1364
  }
1356
1365
 
@@ -1359,18 +1368,22 @@ class ObjectField extends React.Component {
1359
1368
  onChange,
1360
1369
  registry
1361
1370
  } = this.props;
1362
- let type = schema.additionalProperties.type;
1363
1371
  const newFormData = { ...formData
1364
1372
  };
1365
-
1366
- if (utils.REF_KEY in schema.additionalProperties) {
1367
- const {
1368
- schemaUtils
1369
- } = registry;
1370
- const refSchema = schemaUtils.retrieveSchema({
1371
- $ref: schema.additionalProperties[utils.REF_KEY]
1372
- }, formData);
1373
- type = refSchema.type;
1373
+ let type = undefined;
1374
+
1375
+ if (isObject__default["default"](schema.additionalProperties)) {
1376
+ type = schema.additionalProperties.type;
1377
+
1378
+ if (utils.REF_KEY in schema.additionalProperties) {
1379
+ const {
1380
+ schemaUtils
1381
+ } = registry;
1382
+ const refSchema = schemaUtils.retrieveSchema({
1383
+ $ref: schema.additionalProperties[utils.REF_KEY]
1384
+ }, formData);
1385
+ type = refSchema.type;
1386
+ }
1374
1387
  }
1375
1388
 
1376
1389
  const newKey = this.getAvailableKey("newKey", newFormData); // Cast this to make the `set` work properly
@@ -1633,7 +1646,16 @@ function SchemaFieldRender(props) {
1633
1646
  const FieldHelpTemplate = utils.getTemplate("FieldHelpTemplate", registry, uiOptions);
1634
1647
  const FieldErrorTemplate = utils.getTemplate("FieldErrorTemplate", registry, uiOptions);
1635
1648
  const schema = schemaUtils.retrieveSchema(_schema, formData);
1636
- const idSchema = utils.mergeObjects(schemaUtils.toIdSchema(schema, _idSchema.$id, formData, idPrefix, idSeparator), _idSchema);
1649
+ const fieldId = _idSchema[utils.ID_KEY];
1650
+ const idSchema = utils.mergeObjects(schemaUtils.toIdSchema(schema, fieldId, formData, idPrefix, idSeparator), _idSchema);
1651
+ /** Intermediary `onChange` handler for field components that will inject the `id` of the current field into the
1652
+ * `onChange` chain if it is not already being provided from a deeper level in the hierarchy
1653
+ */
1654
+
1655
+ const handleFieldComponentChange = React__default["default"].useCallback((formData, newErrorSchema, id) => {
1656
+ const theId = id || fieldId;
1657
+ return onChange(formData, newErrorSchema, theId);
1658
+ }, [fieldId, onChange]);
1637
1659
  const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
1638
1660
  const disabled = Boolean(props.disabled || uiOptions.disabled);
1639
1661
  const readonly = Boolean(props.readonly || uiOptions.readonly || props.schema.readOnly || schema.readOnly);
@@ -1659,6 +1681,7 @@ function SchemaFieldRender(props) {
1659
1681
  }
1660
1682
 
1661
1683
  const field = /*#__PURE__*/React__default["default"].createElement(FieldComponent, { ...props,
1684
+ onChange: handleFieldComponentChange,
1662
1685
  idSchema: idSchema,
1663
1686
  schema: schema,
1664
1687
  uiSchema: fieldUiSchema,
@@ -1721,6 +1744,8 @@ function SchemaFieldRender(props) {
1721
1744
  description: /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
1722
1745
  id: id + "__description",
1723
1746
  description: description,
1747
+ schema: schema,
1748
+ uiSchema: uiSchema,
1724
1749
  registry: registry
1725
1750
  }),
1726
1751
  rawDescription: description,
@@ -1916,19 +1941,25 @@ function ArrayFieldDescriptionTemplate(props) {
1916
1941
  idSchema,
1917
1942
  description,
1918
1943
  registry,
1944
+ schema,
1919
1945
  uiSchema
1920
1946
  } = props;
1947
+ const options = utils.getUiOptions(uiSchema);
1948
+ const {
1949
+ label: displayLabel = true
1950
+ } = options;
1921
1951
 
1922
- if (!description) {
1952
+ if (!description || !displayLabel) {
1923
1953
  return null;
1924
1954
  }
1925
1955
 
1926
- const options = utils.getUiOptions(uiSchema);
1927
1956
  const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
1928
1957
  const id = idSchema.$id + "__description";
1929
1958
  return /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
1930
1959
  id: id,
1931
1960
  description: description,
1961
+ schema: schema,
1962
+ uiSchema: uiSchema,
1932
1963
  registry: registry
1933
1964
  });
1934
1965
  }
@@ -2032,11 +2063,13 @@ function ArrayFieldTemplate(props) {
2032
2063
  idSchema: idSchema,
2033
2064
  title: uiOptions.title || title,
2034
2065
  required: required,
2066
+ schema: schema,
2035
2067
  uiSchema: uiSchema,
2036
2068
  registry: registry
2037
- }), (uiOptions.description || schema.description) && /*#__PURE__*/React__default["default"].createElement(ArrayFieldDescriptionTemplate, {
2069
+ }), /*#__PURE__*/React__default["default"].createElement(ArrayFieldDescriptionTemplate, {
2038
2070
  idSchema: idSchema,
2039
2071
  description: uiOptions.description || schema.description,
2072
+ schema: schema,
2040
2073
  uiSchema: uiSchema,
2041
2074
  registry: registry
2042
2075
  }), /*#__PURE__*/React__default["default"].createElement("div", {
@@ -2068,22 +2101,27 @@ function ArrayFieldTitleTemplate(props) {
2068
2101
  const {
2069
2102
  idSchema,
2070
2103
  title,
2104
+ schema,
2071
2105
  uiSchema,
2072
2106
  required,
2073
2107
  registry
2074
2108
  } = props;
2109
+ const options = utils.getUiOptions(uiSchema);
2110
+ const {
2111
+ label: displayLabel = true
2112
+ } = options;
2075
2113
 
2076
- if (!title) {
2114
+ if (!title || !displayLabel) {
2077
2115
  return null;
2078
2116
  }
2079
2117
 
2080
- const options = utils.getUiOptions(uiSchema);
2081
2118
  const TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, options);
2082
2119
  const id = idSchema.$id + "__title";
2083
2120
  return /*#__PURE__*/React__default["default"].createElement(TitleFieldTemplate, {
2084
2121
  id: id,
2085
2122
  title: title,
2086
2123
  required: required,
2124
+ schema: schema,
2087
2125
  uiSchema: uiSchema,
2088
2126
  registry: registry
2089
2127
  });
@@ -2488,11 +2526,14 @@ function ObjectFieldTemplate(props) {
2488
2526
  id: idSchema.$id + "__title",
2489
2527
  title: options.title || title,
2490
2528
  required: required,
2529
+ schema: schema,
2491
2530
  uiSchema: uiSchema,
2492
2531
  registry: registry
2493
2532
  }), (options.description || description) && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
2494
2533
  id: idSchema.$id + "__description",
2495
2534
  description: options.description || description,
2535
+ schema: schema,
2536
+ uiSchema: uiSchema,
2496
2537
  registry: registry
2497
2538
  }), properties.map(prop => prop.content), utils.canExpand(schema, uiSchema, formData) && /*#__PURE__*/React__default["default"].createElement(AddButton, {
2498
2539
  className: "object-property-expand",
@@ -2840,6 +2881,7 @@ function AltDateTimeWidget(_ref) {
2840
2881
  function CheckboxWidget(_ref) {
2841
2882
  let {
2842
2883
  schema,
2884
+ uiSchema,
2843
2885
  options,
2844
2886
  id,
2845
2887
  value,
@@ -2865,6 +2907,8 @@ function CheckboxWidget(_ref) {
2865
2907
  }, schema.description && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
2866
2908
  id: id + "__description",
2867
2909
  description: schema.description,
2910
+ schema: schema,
2911
+ uiSchema: uiSchema,
2868
2912
  registry: registry
2869
2913
  }), /*#__PURE__*/React__default["default"].createElement("label", null, /*#__PURE__*/React__default["default"].createElement("input", {
2870
2914
  type: "checkbox",
@@ -3587,7 +3631,7 @@ class Form extends React.Component {
3587
3631
  return getAllPaths(pathSchema);
3588
3632
  };
3589
3633
 
3590
- this.onChange = (formData, newErrorSchema) => {
3634
+ this.onChange = (formData, newErrorSchema, id) => {
3591
3635
  const {
3592
3636
  extraErrors,
3593
3637
  omitExtraData,
@@ -3654,7 +3698,7 @@ class Form extends React.Component {
3654
3698
 
3655
3699
  this.setState(state, () => onChange && onChange({ ...this.state,
3656
3700
  ...state
3657
- }));
3701
+ }, id));
3658
3702
  };
3659
3703
 
3660
3704
  this.onBlur = (id, data) => {