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

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.
Files changed (63) hide show
  1. package/README.md +2 -0
  2. package/dist/core.cjs.development.js +272 -202
  3. package/dist/core.cjs.development.js.map +1 -1
  4. package/dist/core.cjs.production.min.js +1 -1
  5. package/dist/core.cjs.production.min.js.map +1 -1
  6. package/dist/core.esm.js +272 -202
  7. package/dist/core.esm.js.map +1 -1
  8. package/dist/core.umd.development.js +272 -202
  9. package/dist/core.umd.development.js.map +1 -1
  10. package/dist/core.umd.production.min.js +1 -1
  11. package/dist/core.umd.production.min.js.map +1 -1
  12. package/dist/index.d.ts +303 -6
  13. package/package.json +9 -7
  14. package/dist/components/Form.d.ts +0 -277
  15. package/dist/components/fields/ArrayField.d.ts +0 -6
  16. package/dist/components/fields/BooleanField.d.ts +0 -8
  17. package/dist/components/fields/MultiSchemaField.d.ts +0 -44
  18. package/dist/components/fields/NullField.d.ts +0 -8
  19. package/dist/components/fields/NumberField.d.ts +0 -20
  20. package/dist/components/fields/ObjectField.d.ts +0 -73
  21. package/dist/components/fields/SchemaField.d.ts +0 -10
  22. package/dist/components/fields/StringField.d.ts +0 -7
  23. package/dist/components/fields/index.d.ts +0 -3
  24. package/dist/components/templates/ArrayFieldDescriptionTemplate.d.ts +0 -7
  25. package/dist/components/templates/ArrayFieldItemTemplate.d.ts +0 -6
  26. package/dist/components/templates/ArrayFieldTemplate.d.ts +0 -6
  27. package/dist/components/templates/ArrayFieldTitleTemplate.d.ts +0 -7
  28. package/dist/components/templates/BaseInputTemplate.d.ts +0 -8
  29. package/dist/components/templates/ButtonTemplates/AddButton.d.ts +0 -4
  30. package/dist/components/templates/ButtonTemplates/IconButton.d.ts +0 -5
  31. package/dist/components/templates/ButtonTemplates/SubmitButton.d.ts +0 -4
  32. package/dist/components/templates/ButtonTemplates/index.d.ts +0 -3
  33. package/dist/components/templates/DescriptionField.d.ts +0 -6
  34. package/dist/components/templates/ErrorList.d.ts +0 -6
  35. package/dist/components/templates/FieldTemplate/FieldTemplate.d.ts +0 -7
  36. package/dist/components/templates/FieldTemplate/Label.d.ts +0 -13
  37. package/dist/components/templates/FieldTemplate/WrapIfAdditional.d.ts +0 -12
  38. package/dist/components/templates/FieldTemplate/index.d.ts +0 -2
  39. package/dist/components/templates/ObjectFieldTemplate.d.ts +0 -8
  40. package/dist/components/templates/TitleField.d.ts +0 -6
  41. package/dist/components/templates/UnsupportedField.d.ts +0 -8
  42. package/dist/components/templates/index.d.ts +0 -3
  43. package/dist/components/widgets/AltDateTimeWidget.d.ts +0 -8
  44. package/dist/components/widgets/AltDateWidget.d.ts +0 -6
  45. package/dist/components/widgets/CheckboxWidget.d.ts +0 -8
  46. package/dist/components/widgets/CheckboxesWidget.d.ts +0 -8
  47. package/dist/components/widgets/ColorWidget.d.ts +0 -7
  48. package/dist/components/widgets/DateTimeWidget.d.ts +0 -7
  49. package/dist/components/widgets/DateWidget.d.ts +0 -7
  50. package/dist/components/widgets/EmailWidget.d.ts +0 -6
  51. package/dist/components/widgets/FileWidget.d.ts +0 -7
  52. package/dist/components/widgets/HiddenWidget.d.ts +0 -8
  53. package/dist/components/widgets/PasswordWidget.d.ts +0 -6
  54. package/dist/components/widgets/RadioWidget.d.ts +0 -8
  55. package/dist/components/widgets/RangeWidget.d.ts +0 -7
  56. package/dist/components/widgets/SelectWidget.d.ts +0 -8
  57. package/dist/components/widgets/TextWidget.d.ts +0 -6
  58. package/dist/components/widgets/TextareaWidget.d.ts +0 -13
  59. package/dist/components/widgets/URLWidget.d.ts +0 -6
  60. package/dist/components/widgets/UpDownWidget.d.ts +0 -6
  61. package/dist/components/widgets/index.d.ts +0 -3
  62. package/dist/getDefaultRegistry.d.ts +0 -6
  63. package/dist/withTheme.d.ts +0 -8
@@ -784,9 +784,11 @@ class ArrayField extends React.Component {
784
784
  } = this.props;
785
785
  const {
786
786
  fields: {
787
+ ArraySchemaField,
787
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(SchemaField, {
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
 
@@ -1595,58 +1598,6 @@ function getFieldComponent(schema, uiOptions, idSchema, registry) {
1595
1598
  });
1596
1599
  };
1597
1600
  }
1598
- /** The `Help` component renders any help desired for a field
1599
- *
1600
- * @param props - The id and help information to be rendered
1601
- */
1602
-
1603
-
1604
- function Help(props) {
1605
- const {
1606
- id,
1607
- help
1608
- } = props;
1609
-
1610
- if (!help) {
1611
- return null;
1612
- }
1613
-
1614
- if (typeof help === "string") {
1615
- return /*#__PURE__*/React__default["default"].createElement("p", {
1616
- id: id,
1617
- className: "help-block"
1618
- }, help);
1619
- }
1620
-
1621
- return /*#__PURE__*/React__default["default"].createElement("div", {
1622
- id: id,
1623
- className: "help-block"
1624
- }, help);
1625
- }
1626
- /** The `ErrorList` component renders the errors local to the particular field
1627
- *
1628
- * @param props - The list of errors to show
1629
- */
1630
-
1631
-
1632
- function ErrorList$1(props) {
1633
- const {
1634
- errors = []
1635
- } = props;
1636
-
1637
- if (errors.length === 0) {
1638
- return null;
1639
- }
1640
-
1641
- return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("ul", {
1642
- className: "error-detail bs-callout bs-callout-info"
1643
- }, errors.filter(elem => !!elem).map((error, index) => {
1644
- return /*#__PURE__*/React__default["default"].createElement("li", {
1645
- className: "text-danger",
1646
- key: index
1647
- }, error);
1648
- })));
1649
- }
1650
1601
  /** The `SchemaFieldRender` component is the work-horse of react-jsonschema-form, determining what kind of real field to
1651
1602
  * render based on the `schema`, `uiSchema` and all the other props. It also deals with rendering the `anyOf` and
1652
1603
  * `oneOf` fields.
@@ -1679,6 +1630,8 @@ function SchemaFieldRender(props) {
1679
1630
  const uiOptions = utils.getUiOptions(uiSchema);
1680
1631
  const FieldTemplate = utils.getTemplate("FieldTemplate", registry, uiOptions);
1681
1632
  const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, uiOptions);
1633
+ const FieldHelpTemplate = utils.getTemplate("FieldHelpTemplate", registry, uiOptions);
1634
+ const FieldErrorTemplate = utils.getTemplate("FieldErrorTemplate", registry, uiOptions);
1682
1635
  const schema = schemaUtils.retrieveSchema(_schema, formData);
1683
1636
  const idSchema = utils.mergeObjects(schemaUtils.toIdSchema(schema, _idSchema.$id, formData, idPrefix, idSeparator), _idSchema);
1684
1637
  const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
@@ -1724,16 +1677,15 @@ function SchemaFieldRender(props) {
1724
1677
  if (wasPropertyKeyModified) {
1725
1678
  label = name;
1726
1679
  } else {
1727
- label = uiOptions.title || props.schema.title || schema.title || name;
1680
+ label = utils.ADDITIONAL_PROPERTY_FLAG in schema ? name : uiOptions.title || props.schema.title || schema.title || name;
1728
1681
  }
1729
1682
 
1730
1683
  const description = uiOptions.description || props.schema.description || schema.description || "";
1731
- const errors = __errors;
1732
1684
  const help = uiOptions.help;
1733
1685
  const hidden = uiOptions.widget === "hidden";
1734
1686
  const classNames = ["form-group", "field", "field-" + schema.type];
1735
1687
 
1736
- if (!hideError && errors && errors.length > 0) {
1688
+ if (!hideError && __errors && __errors.length > 0) {
1737
1689
  classNames.push("field-error has-error has-danger");
1738
1690
  }
1739
1691
 
@@ -1749,6 +1701,22 @@ function SchemaFieldRender(props) {
1749
1701
  classNames.push(uiOptions.classNames);
1750
1702
  }
1751
1703
 
1704
+ const helpComponent = /*#__PURE__*/React__default["default"].createElement(FieldHelpTemplate, {
1705
+ help: help,
1706
+ idSchema: idSchema,
1707
+ schema: schema,
1708
+ uiSchema: uiSchema,
1709
+ hasErrors: !hideError && __errors && __errors.length > 0,
1710
+ registry: registry
1711
+ });
1712
+ const errorsComponent = hideError ? undefined : /*#__PURE__*/React__default["default"].createElement(FieldErrorTemplate, {
1713
+ errors: __errors,
1714
+ errorSchema: errorSchema,
1715
+ idSchema: idSchema,
1716
+ schema: schema,
1717
+ uiSchema: uiSchema,
1718
+ registry: registry
1719
+ });
1752
1720
  const fieldProps = {
1753
1721
  description: /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
1754
1722
  id: id + "__description",
@@ -1756,15 +1724,10 @@ function SchemaFieldRender(props) {
1756
1724
  registry: registry
1757
1725
  }),
1758
1726
  rawDescription: description,
1759
- help: /*#__PURE__*/React__default["default"].createElement(Help, {
1760
- id: id + "__help",
1761
- help: help
1762
- }),
1727
+ help: helpComponent,
1763
1728
  rawHelp: typeof help === "string" ? help : undefined,
1764
- errors: hideError ? undefined : /*#__PURE__*/React__default["default"].createElement(ErrorList$1, {
1765
- errors: errors
1766
- }),
1767
- rawErrors: hideError ? undefined : errors,
1729
+ errors: errorsComponent,
1730
+ rawErrors: hideError ? undefined : __errors,
1768
1731
  id,
1769
1732
  label,
1770
1733
  hidden,
@@ -1932,6 +1895,7 @@ function NullField(props) {
1932
1895
  const fields = {
1933
1896
  AnyOfField: AnyOfField,
1934
1897
  ArrayField,
1898
+ // ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
1935
1899
  BooleanField,
1936
1900
  NumberField,
1937
1901
  ObjectField,
@@ -1987,7 +1951,8 @@ function ArrayFieldItemTemplate(props) {
1987
1951
  onDropIndexClick,
1988
1952
  onReorderClick,
1989
1953
  readonly,
1990
- registry
1954
+ registry,
1955
+ uiSchema
1991
1956
  } = props;
1992
1957
  const {
1993
1958
  MoveDownButton,
@@ -2015,15 +1980,18 @@ function ArrayFieldItemTemplate(props) {
2015
1980
  }, (hasMoveUp || hasMoveDown) && /*#__PURE__*/React__default["default"].createElement(MoveUpButton, {
2016
1981
  style: btnStyle,
2017
1982
  disabled: disabled || readonly || !hasMoveUp,
2018
- onClick: onReorderClick(index, index - 1)
1983
+ onClick: onReorderClick(index, index - 1),
1984
+ uiSchema: uiSchema
2019
1985
  }), (hasMoveUp || hasMoveDown) && /*#__PURE__*/React__default["default"].createElement(MoveDownButton, {
2020
1986
  style: btnStyle,
2021
1987
  disabled: disabled || readonly || !hasMoveDown,
2022
- onClick: onReorderClick(index, index + 1)
1988
+ onClick: onReorderClick(index, index + 1),
1989
+ uiSchema: uiSchema
2023
1990
  }), hasRemove && /*#__PURE__*/React__default["default"].createElement(RemoveButton, {
2024
1991
  style: btnStyle,
2025
1992
  disabled: disabled || readonly,
2026
- onClick: onDropIndexClick(index)
1993
+ onClick: onDropIndexClick(index),
1994
+ uiSchema: uiSchema
2027
1995
  }))));
2028
1996
  }
2029
1997
 
@@ -2085,7 +2053,8 @@ function ArrayFieldTemplate(props) {
2085
2053
  })), canAdd && /*#__PURE__*/React__default["default"].createElement(AddButton, {
2086
2054
  className: "array-item-add",
2087
2055
  onClick: onAddClick,
2088
- disabled: disabled || readonly
2056
+ disabled: disabled || readonly,
2057
+ uiSchema: uiSchema
2089
2058
  }));
2090
2059
  }
2091
2060
 
@@ -2192,8 +2161,8 @@ function BaseInputTemplate(props) {
2192
2161
  }, [onFocus, id]);
2193
2162
 
2194
2163
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("input", {
2195
- key: id,
2196
2164
  id: id,
2165
+ name: id,
2197
2166
  className: "form-control",
2198
2167
  readOnly: readonly,
2199
2168
  disabled: disabled,
@@ -2242,6 +2211,7 @@ function IconButton(props) {
2242
2211
  iconType = "default",
2243
2212
  icon,
2244
2213
  className,
2214
+ uiSchema,
2245
2215
  ...otherProps
2246
2216
  } = props;
2247
2217
  return /*#__PURE__*/React__default["default"].createElement("button", {
@@ -2387,71 +2357,6 @@ function Label(props) {
2387
2357
  }, REQUIRED_FIELD_SYMBOL$1));
2388
2358
  }
2389
2359
 
2390
- /** The `WrapIfAdditional` component is used by the `FieldTemplate` to rename, or remove properties that are
2391
- * part of an `additionalProperties` part of a schema.
2392
- *
2393
- * @param props - The `WrapIfAdditionalProps` for this component
2394
- */
2395
-
2396
- function WrapIfAdditional(props) {
2397
- const {
2398
- id,
2399
- classNames,
2400
- disabled,
2401
- label,
2402
- onKeyChange,
2403
- onDropPropertyClick,
2404
- readonly,
2405
- required,
2406
- schema,
2407
- children,
2408
- registry
2409
- } = props;
2410
- const {
2411
- RemoveButton
2412
- } = registry.templates.ButtonTemplates;
2413
- const keyLabel = label + " Key"; // i18n ?
2414
-
2415
- const additional = (utils.ADDITIONAL_PROPERTY_FLAG in schema);
2416
-
2417
- if (!additional) {
2418
- return /*#__PURE__*/React__default["default"].createElement("div", {
2419
- className: classNames
2420
- }, children);
2421
- }
2422
-
2423
- return /*#__PURE__*/React__default["default"].createElement("div", {
2424
- className: classNames
2425
- }, /*#__PURE__*/React__default["default"].createElement("div", {
2426
- className: "row"
2427
- }, /*#__PURE__*/React__default["default"].createElement("div", {
2428
- className: "col-xs-5 form-additional"
2429
- }, /*#__PURE__*/React__default["default"].createElement("div", {
2430
- className: "form-group"
2431
- }, /*#__PURE__*/React__default["default"].createElement(Label, {
2432
- label: keyLabel,
2433
- required: required,
2434
- id: id + "-key"
2435
- }), /*#__PURE__*/React__default["default"].createElement("input", {
2436
- className: "form-control",
2437
- type: "text",
2438
- id: id + "-key",
2439
- onBlur: event => onKeyChange(event.target.value),
2440
- defaultValue: label
2441
- }))), /*#__PURE__*/React__default["default"].createElement("div", {
2442
- className: "form-additional form-group col-xs-5"
2443
- }, children), /*#__PURE__*/React__default["default"].createElement("div", {
2444
- className: "col-xs-2"
2445
- }, /*#__PURE__*/React__default["default"].createElement(RemoveButton, {
2446
- className: "array-item-remove btn-block",
2447
- style: {
2448
- border: "0"
2449
- },
2450
- disabled: disabled || readonly,
2451
- onClick: onDropPropertyClick(label)
2452
- }))));
2453
- }
2454
-
2455
2360
  /** The `FieldTemplate` component is the template used by `SchemaField` to render any field. It renders the field
2456
2361
  * content, (label, description, children, errors and help) inside of a `WrapIfAdditional` component.
2457
2362
  *
@@ -2468,8 +2373,12 @@ function FieldTemplate(props) {
2468
2373
  description,
2469
2374
  hidden,
2470
2375
  required,
2471
- displayLabel
2376
+ displayLabel,
2377
+ registry,
2378
+ uiSchema
2472
2379
  } = props;
2380
+ const uiOptions = utils.getUiOptions(uiSchema);
2381
+ const WrapIfAdditionalTemplate = utils.getTemplate("WrapIfAdditionalTemplate", registry, uiOptions);
2473
2382
 
2474
2383
  if (hidden) {
2475
2384
  return /*#__PURE__*/React__default["default"].createElement("div", {
@@ -2477,7 +2386,7 @@ function FieldTemplate(props) {
2477
2386
  }, children);
2478
2387
  }
2479
2388
 
2480
- return /*#__PURE__*/React__default["default"].createElement(WrapIfAdditional, { ...props
2389
+ return /*#__PURE__*/React__default["default"].createElement(WrapIfAdditionalTemplate, { ...props
2481
2390
  }, displayLabel && /*#__PURE__*/React__default["default"].createElement(Label, {
2482
2391
  label: label,
2483
2392
  required: required,
@@ -2485,6 +2394,63 @@ function FieldTemplate(props) {
2485
2394
  }), displayLabel && description ? description : null, children, errors, help);
2486
2395
  }
2487
2396
 
2397
+ /** The `FieldErrorTemplate` component renders the errors local to the particular field
2398
+ *
2399
+ * @param props - The `FieldErrorProps` for the errors being rendered
2400
+ */
2401
+
2402
+ function FieldErrorTemplate(props) {
2403
+ const {
2404
+ errors = [],
2405
+ idSchema
2406
+ } = props;
2407
+
2408
+ if (errors.length === 0) {
2409
+ return null;
2410
+ }
2411
+
2412
+ const id = idSchema.$id + "__error";
2413
+ return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("ul", {
2414
+ id: id,
2415
+ className: "error-detail bs-callout bs-callout-info"
2416
+ }, errors.filter(elem => !!elem).map((error, index) => {
2417
+ return /*#__PURE__*/React__default["default"].createElement("li", {
2418
+ className: "text-danger",
2419
+ key: index
2420
+ }, error);
2421
+ })));
2422
+ }
2423
+
2424
+ /** The `FieldHelpTemplate` component renders any help desired for a field
2425
+ *
2426
+ * @param props - The `FieldHelpProps` to be rendered
2427
+ */
2428
+
2429
+ function FieldHelpTemplate(props) {
2430
+ const {
2431
+ idSchema,
2432
+ help
2433
+ } = props;
2434
+
2435
+ if (!help) {
2436
+ return null;
2437
+ }
2438
+
2439
+ const id = idSchema.$id + "__help";
2440
+
2441
+ if (typeof help === "string") {
2442
+ return /*#__PURE__*/React__default["default"].createElement("p", {
2443
+ id: id,
2444
+ className: "help-block"
2445
+ }, help);
2446
+ }
2447
+
2448
+ return /*#__PURE__*/React__default["default"].createElement("div", {
2449
+ id: id,
2450
+ className: "help-block"
2451
+ }, help);
2452
+ }
2453
+
2488
2454
  /** The `ObjectFieldTemplate` is the template to use to render all the inner properties of an object along with the
2489
2455
  * title and description if available. If the object is expandable, then an `AddButton` is also rendered after all
2490
2456
  * the properties.
@@ -2531,7 +2497,8 @@ function ObjectFieldTemplate(props) {
2531
2497
  }), properties.map(prop => prop.content), utils.canExpand(schema, uiSchema, formData) && /*#__PURE__*/React__default["default"].createElement(AddButton, {
2532
2498
  className: "object-property-expand",
2533
2499
  onClick: onAddClick(schema),
2534
- disabled: disabled || readonly
2500
+ disabled: disabled || readonly,
2501
+ uiSchema: uiSchema
2535
2502
  }));
2536
2503
  }
2537
2504
 
@@ -2571,6 +2538,74 @@ function UnsupportedField(props) {
2571
2538
  }, /*#__PURE__*/React__default["default"].createElement("p", null, "Unsupported field schema", idSchema && idSchema.$id && /*#__PURE__*/React__default["default"].createElement("span", null, " for", " field ", /*#__PURE__*/React__default["default"].createElement("code", null, idSchema.$id)), reason && /*#__PURE__*/React__default["default"].createElement("em", null, ": ", reason), "."), schema && /*#__PURE__*/React__default["default"].createElement("pre", null, JSON.stringify(schema, null, 2)));
2572
2539
  }
2573
2540
 
2541
+ /** The `WrapIfAdditional` component is used by the `FieldTemplate` to rename, or remove properties that are
2542
+ * part of an `additionalProperties` part of a schema.
2543
+ *
2544
+ * @param props - The `WrapIfAdditionalProps` for this component
2545
+ */
2546
+
2547
+ function WrapIfAdditionalTemplate(props) {
2548
+ const {
2549
+ id,
2550
+ classNames,
2551
+ disabled,
2552
+ label,
2553
+ onKeyChange,
2554
+ onDropPropertyClick,
2555
+ readonly,
2556
+ required,
2557
+ schema,
2558
+ children,
2559
+ uiSchema,
2560
+ registry
2561
+ } = props; // Button templates are not overridden in the uiSchema
2562
+
2563
+ const {
2564
+ RemoveButton
2565
+ } = registry.templates.ButtonTemplates;
2566
+ const keyLabel = label + " Key"; // i18n ?
2567
+
2568
+ const additional = (utils.ADDITIONAL_PROPERTY_FLAG in schema);
2569
+
2570
+ if (!additional) {
2571
+ return /*#__PURE__*/React__default["default"].createElement("div", {
2572
+ className: classNames
2573
+ }, children);
2574
+ }
2575
+
2576
+ return /*#__PURE__*/React__default["default"].createElement("div", {
2577
+ className: classNames
2578
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
2579
+ className: "row"
2580
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
2581
+ className: "col-xs-5 form-additional"
2582
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
2583
+ className: "form-group"
2584
+ }, /*#__PURE__*/React__default["default"].createElement(Label, {
2585
+ label: keyLabel,
2586
+ required: required,
2587
+ id: id + "-key"
2588
+ }), /*#__PURE__*/React__default["default"].createElement("input", {
2589
+ className: "form-control",
2590
+ type: "text",
2591
+ id: id + "-key",
2592
+ onBlur: event => onKeyChange(event.target.value),
2593
+ defaultValue: label
2594
+ }))), /*#__PURE__*/React__default["default"].createElement("div", {
2595
+ className: "form-additional form-group col-xs-5"
2596
+ }, children), /*#__PURE__*/React__default["default"].createElement("div", {
2597
+ className: "col-xs-2"
2598
+ }, /*#__PURE__*/React__default["default"].createElement(RemoveButton, {
2599
+ className: "array-item-remove btn-block",
2600
+ style: {
2601
+ border: "0"
2602
+ },
2603
+ disabled: disabled || readonly,
2604
+ onClick: onDropPropertyClick(label),
2605
+ uiSchema: uiSchema
2606
+ }))));
2607
+ }
2608
+
2574
2609
  const templates = {
2575
2610
  ArrayFieldDescriptionTemplate,
2576
2611
  ArrayFieldItemTemplate,
@@ -2581,9 +2616,12 @@ const templates = {
2581
2616
  DescriptionFieldTemplate: DescriptionField,
2582
2617
  ErrorListTemplate: ErrorList,
2583
2618
  FieldTemplate,
2619
+ FieldErrorTemplate,
2620
+ FieldHelpTemplate,
2584
2621
  ObjectFieldTemplate,
2585
2622
  TitleFieldTemplate: TitleField,
2586
- UnsupportedFieldTemplate: UnsupportedField
2623
+ UnsupportedFieldTemplate: UnsupportedField,
2624
+ WrapIfAdditionalTemplate
2587
2625
  };
2588
2626
 
2589
2627
  function rangeOptions(start, stop) {
@@ -2831,6 +2869,7 @@ function CheckboxWidget(_ref) {
2831
2869
  }), /*#__PURE__*/React__default["default"].createElement("label", null, /*#__PURE__*/React__default["default"].createElement("input", {
2832
2870
  type: "checkbox",
2833
2871
  id: id,
2872
+ name: id,
2834
2873
  checked: typeof value === "undefined" ? false : value,
2835
2874
  required: required,
2836
2875
  disabled: disabled || readonly,
@@ -2878,7 +2917,7 @@ function CheckboxesWidget(_ref) {
2878
2917
  id: id
2879
2918
  }, Array.isArray(enumOptions) && enumOptions.map((option, index) => {
2880
2919
  const checked = value.indexOf(option.value) !== -1;
2881
- const itemDisabled = enumDisabled && enumDisabled.indexOf(option.value) != -1;
2920
+ const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) != -1;
2882
2921
  const disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
2883
2922
 
2884
2923
  const handleChange = event => {
@@ -2898,17 +2937,18 @@ function CheckboxesWidget(_ref) {
2898
2937
 
2899
2938
  const checkbox = /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement("input", {
2900
2939
  type: "checkbox",
2901
- id: id + "_" + index,
2940
+ id: id + "-" + option.value,
2941
+ name: id,
2902
2942
  checked: checked,
2903
2943
  disabled: disabled || itemDisabled || readonly,
2904
2944
  autoFocus: autofocus && index === 0,
2905
2945
  onChange: handleChange
2906
2946
  }), /*#__PURE__*/React__default["default"].createElement("span", null, option.label));
2907
2947
  return inline ? /*#__PURE__*/React__default["default"].createElement("label", {
2908
- key: index,
2948
+ key: option.value,
2909
2949
  className: "checkbox-inline " + disabledCls
2910
2950
  }, checkbox) : /*#__PURE__*/React__default["default"].createElement("div", {
2911
- key: index,
2951
+ key: option.value,
2912
2952
  className: "checkbox " + disabledCls
2913
2953
  }, /*#__PURE__*/React__default["default"].createElement("label", null, checkbox));
2914
2954
  }));
@@ -3114,6 +3154,7 @@ function FileWidget(_ref2) {
3114
3154
  }, [multiple, onChange]);
3115
3155
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("p", null, /*#__PURE__*/React__default["default"].createElement("input", {
3116
3156
  id: id,
3157
+ name: id,
3117
3158
  type: "file",
3118
3159
  disabled: readonly || disabled,
3119
3160
  onChange: handleChange,
@@ -3140,6 +3181,7 @@ function HiddenWidget(_ref) {
3140
3181
  return /*#__PURE__*/React__default["default"].createElement("input", {
3141
3182
  type: "hidden",
3142
3183
  id: id,
3184
+ name: id,
3143
3185
  value: typeof value === "undefined" ? "" : value
3144
3186
  });
3145
3187
  }
@@ -3196,14 +3238,14 @@ function RadioWidget(_ref) {
3196
3238
  id: id
3197
3239
  }, Array.isArray(enumOptions) && enumOptions.map((option, i) => {
3198
3240
  const checked = option.value === value;
3199
- const itemDisabled = enumDisabled && enumDisabled.indexOf(option.value) != -1;
3241
+ const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) != -1;
3200
3242
  const disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
3201
3243
 
3202
3244
  const handleChange = () => onChange(option.value);
3203
3245
 
3204
3246
  const radio = /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement("input", {
3205
3247
  type: "radio",
3206
- id: id + "_" + i,
3248
+ id: id + "-" + option.value,
3207
3249
  checked: checked,
3208
3250
  name: name,
3209
3251
  required: required,
@@ -3215,10 +3257,10 @@ function RadioWidget(_ref) {
3215
3257
  onFocus: handleFocus
3216
3258
  }), /*#__PURE__*/React__default["default"].createElement("span", null, option.label));
3217
3259
  return inline ? /*#__PURE__*/React__default["default"].createElement("label", {
3218
- key: i,
3260
+ key: option.value,
3219
3261
  className: "radio-inline " + disabledCls
3220
3262
  }, radio) : /*#__PURE__*/React__default["default"].createElement("div", {
3221
- key: i,
3263
+ key: option.value,
3222
3264
  className: "radio " + disabledCls
3223
3265
  }, /*#__PURE__*/React__default["default"].createElement("label", null, radio));
3224
3266
  }));
@@ -3298,6 +3340,7 @@ function SelectWidget(_ref) {
3298
3340
  }, [onChange, schema, multiple, options]);
3299
3341
  return /*#__PURE__*/React__default["default"].createElement("select", {
3300
3342
  id: id,
3343
+ name: id,
3301
3344
  multiple: multiple,
3302
3345
  className: "form-control",
3303
3346
  value: typeof value === "undefined" ? emptyValue : value,
@@ -3368,6 +3411,7 @@ function TextareaWidget(_ref) {
3368
3411
  }, [id, onFocus]);
3369
3412
  return /*#__PURE__*/React__default["default"].createElement("textarea", {
3370
3413
  id: id,
3414
+ name: id,
3371
3415
  className: "form-control",
3372
3416
  value: value ? value : "",
3373
3417
  placeholder: placeholder,
@@ -3580,7 +3624,7 @@ class Form extends React.Component {
3580
3624
  }
3581
3625
 
3582
3626
  if (mustValidate) {
3583
- const schemaValidation = this.validate(schemaUtils, newFormData);
3627
+ const schemaValidation = this.validate(newFormData);
3584
3628
  let errors = schemaValidation.errors;
3585
3629
  let errorSchema = schemaValidation.errorSchema;
3586
3630
  const schemaValidationErrors = errors;
@@ -3645,8 +3689,7 @@ class Form extends React.Component {
3645
3689
  omitExtraData,
3646
3690
  extraErrors,
3647
3691
  noValidate,
3648
- onSubmit,
3649
- onError
3692
+ onSubmit
3650
3693
  } = this.props;
3651
3694
  let {
3652
3695
  formData: newFormData
@@ -3663,56 +3706,32 @@ class Form extends React.Component {
3663
3706
  newFormData = this.getUsedFormData(newFormData, fieldNames);
3664
3707
  }
3665
3708
 
3666
- if (!noValidate) {
3667
- const schemaValidation = this.validate(schemaUtils, newFormData);
3668
- let errors = schemaValidation.errors;
3669
- let errorSchema = schemaValidation.errorSchema;
3670
- const schemaValidationErrors = errors;
3671
- const schemaValidationErrorSchema = errorSchema;
3672
-
3673
- if (errors.length > 0) {
3674
- if (extraErrors) {
3675
- const merged = schemaUtils.mergeValidationData(schemaValidation, extraErrors);
3676
- errorSchema = merged.errorSchema;
3677
- errors = merged.errors;
3709
+ if (noValidate || this.validateForm()) {
3710
+ // There are no errors generated through schema validation.
3711
+ // Check for user provided errors and update state accordingly.
3712
+ const errorSchema = extraErrors || {};
3713
+ const errors = extraErrors ? schemaUtils.getValidator().toErrorList(extraErrors) : [];
3714
+ this.setState({
3715
+ formData: newFormData,
3716
+ errors,
3717
+ errorSchema,
3718
+ schemaValidationErrors: [],
3719
+ schemaValidationErrorSchema: {}
3720
+ }, () => {
3721
+ if (onSubmit) {
3722
+ onSubmit({ ...this.state,
3723
+ formData: newFormData,
3724
+ status: "submitted"
3725
+ }, event);
3678
3726
  }
3679
-
3680
- this.setState({
3681
- errors,
3682
- errorSchema,
3683
- schemaValidationErrors,
3684
- schemaValidationErrorSchema
3685
- }, () => {
3686
- if (onError) {
3687
- onError(errors);
3688
- } else {
3689
- console.error("Form validation failed", errors);
3690
- }
3691
- });
3692
- return;
3693
- }
3694
- } // There are no errors generated through schema validation.
3695
- // Check for user provided errors and update state accordingly.
3696
-
3697
-
3698
- const errorSchema = extraErrors || {};
3699
- const errors = extraErrors ? schemaUtils.getValidator().toErrorList(extraErrors) : [];
3700
- this.setState({
3701
- formData: newFormData,
3702
- errors,
3703
- errorSchema,
3704
- schemaValidationErrors: [],
3705
- schemaValidationErrorSchema: {}
3706
- }, () => {
3707
- if (onSubmit) {
3708
- onSubmit({ ...this.state,
3709
- formData: newFormData,
3710
- status: "submitted"
3711
- }, event);
3712
- }
3713
- });
3727
+ });
3728
+ }
3714
3729
  };
3715
3730
 
3731
+ if (!props.validator) {
3732
+ throw new Error("A validator is required for Form functionality to work");
3733
+ }
3734
+
3716
3735
  this.state = this.getStateFromProps(props, props.formData);
3717
3736
 
3718
3737
  if (this.props.onChange && !utils.deepEquals(this.state.formData, this.props.formData)) {
@@ -3790,7 +3809,7 @@ class Form extends React.Component {
3790
3809
  let schemaValidationErrorSchema = state.schemaValidationErrorSchema;
3791
3810
 
3792
3811
  if (mustValidate) {
3793
- const schemaValidation = this.validate(schemaUtils, formData, schema);
3812
+ const schemaValidation = this.validate(formData, schema, schemaUtils);
3794
3813
  errors = schemaValidation.errors;
3795
3814
  errorSchema = schemaValidation.errorSchema;
3796
3815
  schemaValidationErrors = errors;
@@ -3836,19 +3855,21 @@ class Form extends React.Component {
3836
3855
  shouldComponentUpdate(nextProps, nextState) {
3837
3856
  return utils.shouldRender(this, nextProps, nextState);
3838
3857
  }
3839
- /** Validates the `formData` against the `schema` using the `schemaUtils`, returning the results.
3858
+ /** Validates the `formData` against the `schema` using the `altSchemaUtils` (if provided otherwise it uses the
3859
+ * `schemaUtils` in the state), returning the results.
3840
3860
  *
3841
- * @param schemaUtils - The schemaUtils to use for validation
3842
3861
  * @param formData - The new form data to validate
3843
3862
  * @param schema - The schema used to validate against
3863
+ * @param altSchemaUtils - The alternate schemaUtils to use for validation
3844
3864
  */
3845
3865
 
3846
3866
 
3847
- validate(schemaUtils, formData, schema) {
3867
+ validate(formData, schema, altSchemaUtils) {
3848
3868
  if (schema === void 0) {
3849
3869
  schema = this.props.schema;
3850
3870
  }
3851
3871
 
3872
+ const schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
3852
3873
  const {
3853
3874
  customValidate,
3854
3875
  transformErrors
@@ -3931,8 +3952,57 @@ class Form extends React.Component {
3931
3952
  this.formElement.current.dispatchEvent(new CustomEvent("submit", {
3932
3953
  cancelable: true
3933
3954
  }));
3955
+ this.formElement.current.requestSubmit();
3934
3956
  }
3935
3957
  }
3958
+ /** Programmatically validate the form. If `onError` is provided, then it will be called with the list of errors the
3959
+ * same way as would happen on form submission.
3960
+ *
3961
+ * @returns - True if the form is valid, false otherwise.
3962
+ */
3963
+
3964
+
3965
+ validateForm() {
3966
+ const {
3967
+ extraErrors,
3968
+ onError
3969
+ } = this.props;
3970
+ const {
3971
+ formData
3972
+ } = this.state;
3973
+ const {
3974
+ schemaUtils
3975
+ } = this.state;
3976
+ const schemaValidation = this.validate(formData);
3977
+ let errors = schemaValidation.errors;
3978
+ let errorSchema = schemaValidation.errorSchema;
3979
+ const schemaValidationErrors = errors;
3980
+ const schemaValidationErrorSchema = errorSchema;
3981
+
3982
+ if (errors.length > 0) {
3983
+ if (extraErrors) {
3984
+ const merged = schemaUtils.mergeValidationData(schemaValidation, extraErrors);
3985
+ errorSchema = merged.errorSchema;
3986
+ errors = merged.errors;
3987
+ }
3988
+
3989
+ this.setState({
3990
+ errors,
3991
+ errorSchema,
3992
+ schemaValidationErrors,
3993
+ schemaValidationErrorSchema
3994
+ }, () => {
3995
+ if (onError) {
3996
+ onError(errors);
3997
+ } else {
3998
+ console.error("Form validation failed", errors);
3999
+ }
4000
+ });
4001
+ return false;
4002
+ }
4003
+
4004
+ return true;
4005
+ }
3936
4006
  /** Renders the `Form` fields inside the <form> | `tagName` or `_internalFormWrapper`, rendering any errors if
3937
4007
  * needed along with the submit button or any children of the form.
3938
4008
  */