@rjsf/core 5.0.1 → 5.1.0

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/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
  <p align="center">
16
16
  Core logic and classic Bootstrap 3 theme for <a href="https://github.com/rjsf-team/react-jsonschema-form/"><code>react-jsonschema-form</code></a>.
17
17
  <br />
18
- <a href="https://react-jsonschema-form.readthedocs.io/en/stable/"><strong>Explore the docs »</strong></a>
18
+ <a href="https://rjsf-team.github.io/react-jsonschema-form/docs/"><strong>Explore the docs »</strong></a>
19
19
  <br />
20
20
  <br />
21
21
  <a href="https://rjsf-team.github.io/react-jsonschema-form/">View Playground</a>
@@ -88,7 +88,7 @@ See the general [open issues](https://github.com/rjsf-team/react-jsonschema-form
88
88
 
89
89
  ## Contributing
90
90
 
91
- Read our [contributors' guide](https://react-jsonschema-form.readthedocs.io/en/stable/contributing/) to get started.
91
+ Read our [contributors' guide](https://rjsf-team.github.io/react-jsonschema-form/docs/contributing/) to get started.
92
92
 
93
93
  <!-- CONTACT -->
94
94
 
@@ -7,6 +7,7 @@ var utils = require('@rjsf/utils');
7
7
  var get = require('lodash/get');
8
8
  var isEmpty = require('lodash/isEmpty');
9
9
  var _pick = require('lodash/pick');
10
+ var _toPath = require('lodash/toPath');
10
11
  var isObject = require('lodash/isObject');
11
12
  var set = require('lodash/set');
12
13
  var nanoid = require('nanoid');
@@ -20,6 +21,7 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
20
21
  var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
21
22
  var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
22
23
  var _pick__default = /*#__PURE__*/_interopDefaultLegacy(_pick);
24
+ var _toPath__default = /*#__PURE__*/_interopDefaultLegacy(_toPath);
23
25
  var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
24
26
  var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
25
27
  var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
@@ -2643,6 +2645,7 @@ function AltDateWidget(_ref2) {
2643
2645
  className: "list-inline"
2644
2646
  }, dateElementProps(state, time, options.yearsRange).map(function (elemProps, i) {
2645
2647
  return /*#__PURE__*/React__default["default"].createElement("li", {
2648
+ className: "list-inline-item",
2646
2649
  key: i
2647
2650
  }, /*#__PURE__*/React__default["default"].createElement(DateElement, _extends({
2648
2651
  rootId: id,
@@ -2655,11 +2658,15 @@ function AltDateWidget(_ref2) {
2655
2658
  onFocus: onFocus,
2656
2659
  autofocus: autofocus && i === 0
2657
2660
  })));
2658
- }), (options.hideNowButton !== "undefined" ? !options.hideNowButton : true) && /*#__PURE__*/React__default["default"].createElement("li", null, /*#__PURE__*/React__default["default"].createElement("a", {
2661
+ }), (options.hideNowButton !== "undefined" ? !options.hideNowButton : true) && /*#__PURE__*/React__default["default"].createElement("li", {
2662
+ className: "list-inline-item"
2663
+ }, /*#__PURE__*/React__default["default"].createElement("a", {
2659
2664
  href: "#",
2660
2665
  className: "btn btn-info btn-now",
2661
2666
  onClick: handleSetNow
2662
- }, "Now")), (options.hideClearButton !== "undefined" ? !options.hideClearButton : true) && /*#__PURE__*/React__default["default"].createElement("li", null, /*#__PURE__*/React__default["default"].createElement("a", {
2667
+ }, "Now")), (options.hideClearButton !== "undefined" ? !options.hideClearButton : true) && /*#__PURE__*/React__default["default"].createElement("li", {
2668
+ className: "list-inline-item"
2669
+ }, /*#__PURE__*/React__default["default"].createElement("a", {
2663
2670
  href: "#",
2664
2671
  className: "btn btn-warning btn-clear",
2665
2672
  onClick: handleClear
@@ -3532,7 +3539,7 @@ var Form = /*#__PURE__*/function (_Component) {
3532
3539
  if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(props.validator, rootSchema)) {
3533
3540
  schemaUtils = utils.createSchemaUtils(props.validator, rootSchema);
3534
3541
  }
3535
- var formData = schemaUtils.getDefaultFormState(schema, inputFormData, "excludeObjectChildren");
3542
+ var formData = schemaUtils.getDefaultFormState(schema, inputFormData);
3536
3543
  var retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
3537
3544
  var getCurrentErrors = function getCurrentErrors() {
3538
3545
  if (props.noValidate) {
@@ -3672,15 +3679,47 @@ var Form = /*#__PURE__*/function (_Component) {
3672
3679
  this.formElement.current.requestSubmit();
3673
3680
  }
3674
3681
  }
3682
+ /** Attempts to focus on the field associated with the `error`. Uses the `property` field to compute path of the error
3683
+ * field, then, using the `idPrefix` and `idSeparator` converts that path into an id. Then the input element with that
3684
+ * id is attempted to be found using the `formElement` ref. If it is located, then it is focused.
3685
+ *
3686
+ * @param error - The error on which to focus
3687
+ */;
3688
+ _proto.focusOnError = function focusOnError(error) {
3689
+ var _this$props4 = this.props,
3690
+ _this$props4$idPrefix = _this$props4.idPrefix,
3691
+ idPrefix = _this$props4$idPrefix === void 0 ? "root" : _this$props4$idPrefix,
3692
+ _this$props4$idSepara = _this$props4.idSeparator,
3693
+ idSeparator = _this$props4$idSepara === void 0 ? "_" : _this$props4$idSepara;
3694
+ var property = error.property;
3695
+ var path = _toPath__default["default"](property);
3696
+ if (path[0] === "") {
3697
+ // Most of the time the `.foo` property results in the first element being empty, so replace it with the idPrefix
3698
+ path[0] = idPrefix;
3699
+ } else {
3700
+ // Otherwise insert the idPrefix into the first location using unshift
3701
+ path.unshift(idPrefix);
3702
+ }
3703
+ var elementId = path.join(idSeparator);
3704
+ var field = this.formElement.current.elements[elementId];
3705
+ if (!field) {
3706
+ // if not an exact match, try finding an input starting with the element id (like radio buttons or checkboxes)
3707
+ field = this.formElement.current.querySelector("input[id^=" + elementId);
3708
+ }
3709
+ if (field) {
3710
+ field.focus();
3711
+ }
3712
+ }
3675
3713
  /** Programmatically validate the form. If `onError` is provided, then it will be called with the list of errors the
3676
3714
  * same way as would happen on form submission.
3677
3715
  *
3678
3716
  * @returns - True if the form is valid, false otherwise.
3679
3717
  */;
3680
3718
  _proto.validateForm = function validateForm() {
3681
- var _this$props4 = this.props,
3682
- extraErrors = _this$props4.extraErrors,
3683
- onError = _this$props4.onError;
3719
+ var _this$props5 = this.props,
3720
+ extraErrors = _this$props5.extraErrors,
3721
+ focusOnFirstError = _this$props5.focusOnFirstError,
3722
+ onError = _this$props5.onError;
3684
3723
  var formData = this.state.formData;
3685
3724
  var schemaUtils = this.state.schemaUtils;
3686
3725
  var schemaValidation = this.validate(formData);
@@ -3694,6 +3733,9 @@ var Form = /*#__PURE__*/function (_Component) {
3694
3733
  errorSchema = merged.errorSchema;
3695
3734
  errors = merged.errors;
3696
3735
  }
3736
+ if (focusOnFirstError) {
3737
+ this.focusOnError(schemaValidation.errors[0]);
3738
+ }
3697
3739
  this.setState({
3698
3740
  errors: errors,
3699
3741
  errorSchema: errorSchema,
@@ -3714,31 +3756,31 @@ var Form = /*#__PURE__*/function (_Component) {
3714
3756
  * needed along with the submit button or any children of the form.
3715
3757
  */;
3716
3758
  _proto.render = function render() {
3717
- var _this$props5 = this.props,
3718
- children = _this$props5.children,
3719
- id = _this$props5.id,
3720
- idPrefix = _this$props5.idPrefix,
3721
- idSeparator = _this$props5.idSeparator,
3722
- _this$props5$classNam = _this$props5.className,
3723
- className = _this$props5$classNam === void 0 ? "" : _this$props5$classNam,
3724
- tagName = _this$props5.tagName,
3725
- name = _this$props5.name,
3726
- method = _this$props5.method,
3727
- target = _this$props5.target,
3728
- action = _this$props5.action,
3729
- autoComplete = _this$props5.autoComplete,
3730
- enctype = _this$props5.enctype,
3731
- acceptcharset = _this$props5.acceptcharset,
3732
- _this$props5$noHtml5V = _this$props5.noHtml5Validate,
3733
- noHtml5Validate = _this$props5$noHtml5V === void 0 ? false : _this$props5$noHtml5V,
3734
- _this$props5$disabled = _this$props5.disabled,
3735
- disabled = _this$props5$disabled === void 0 ? false : _this$props5$disabled,
3736
- _this$props5$readonly = _this$props5.readonly,
3737
- readonly = _this$props5$readonly === void 0 ? false : _this$props5$readonly,
3738
- formContext = _this$props5.formContext,
3739
- _this$props5$showErro = _this$props5.showErrorList,
3740
- showErrorList = _this$props5$showErro === void 0 ? "top" : _this$props5$showErro,
3741
- _internalFormWrapper = _this$props5._internalFormWrapper;
3759
+ var _this$props6 = this.props,
3760
+ children = _this$props6.children,
3761
+ id = _this$props6.id,
3762
+ idPrefix = _this$props6.idPrefix,
3763
+ idSeparator = _this$props6.idSeparator,
3764
+ _this$props6$classNam = _this$props6.className,
3765
+ className = _this$props6$classNam === void 0 ? "" : _this$props6$classNam,
3766
+ tagName = _this$props6.tagName,
3767
+ name = _this$props6.name,
3768
+ method = _this$props6.method,
3769
+ target = _this$props6.target,
3770
+ action = _this$props6.action,
3771
+ autoComplete = _this$props6.autoComplete,
3772
+ enctype = _this$props6.enctype,
3773
+ acceptcharset = _this$props6.acceptcharset,
3774
+ _this$props6$noHtml5V = _this$props6.noHtml5Validate,
3775
+ noHtml5Validate = _this$props6$noHtml5V === void 0 ? false : _this$props6$noHtml5V,
3776
+ _this$props6$disabled = _this$props6.disabled,
3777
+ disabled = _this$props6$disabled === void 0 ? false : _this$props6$disabled,
3778
+ _this$props6$readonly = _this$props6.readonly,
3779
+ readonly = _this$props6$readonly === void 0 ? false : _this$props6$readonly,
3780
+ formContext = _this$props6.formContext,
3781
+ _this$props6$showErro = _this$props6.showErrorList,
3782
+ showErrorList = _this$props6$showErro === void 0 ? "top" : _this$props6$showErro,
3783
+ _internalFormWrapper = _this$props6._internalFormWrapper;
3742
3784
  var _this$state4 = this.state,
3743
3785
  schema = _this$state4.schema,
3744
3786
  uiSchema = _this$state4.uiSchema,