@rjsf/core 5.0.2 → 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/dist/core.esm.js CHANGED
@@ -3,6 +3,7 @@ import { isFixedItems, allowAdditionalItems, getUiOptions, ITEMS_KEY, getTemplat
3
3
  import get from 'lodash-es/get';
4
4
  import isEmpty from 'lodash-es/isEmpty';
5
5
  import _pick from 'lodash-es/pick';
6
+ import _toPath from 'lodash-es/toPath';
6
7
  import isObject from 'lodash-es/isObject';
7
8
  import set from 'lodash-es/set';
8
9
  import { nanoid } from 'nanoid';
@@ -2627,6 +2628,7 @@ function AltDateWidget(_ref2) {
2627
2628
  className: "list-inline"
2628
2629
  }, dateElementProps(state, time, options.yearsRange).map(function (elemProps, i) {
2629
2630
  return /*#__PURE__*/React.createElement("li", {
2631
+ className: "list-inline-item",
2630
2632
  key: i
2631
2633
  }, /*#__PURE__*/React.createElement(DateElement, _extends({
2632
2634
  rootId: id,
@@ -2639,11 +2641,15 @@ function AltDateWidget(_ref2) {
2639
2641
  onFocus: onFocus,
2640
2642
  autofocus: autofocus && i === 0
2641
2643
  })));
2642
- }), (options.hideNowButton !== "undefined" ? !options.hideNowButton : true) && /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("a", {
2644
+ }), (options.hideNowButton !== "undefined" ? !options.hideNowButton : true) && /*#__PURE__*/React.createElement("li", {
2645
+ className: "list-inline-item"
2646
+ }, /*#__PURE__*/React.createElement("a", {
2643
2647
  href: "#",
2644
2648
  className: "btn btn-info btn-now",
2645
2649
  onClick: handleSetNow
2646
- }, "Now")), (options.hideClearButton !== "undefined" ? !options.hideClearButton : true) && /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("a", {
2650
+ }, "Now")), (options.hideClearButton !== "undefined" ? !options.hideClearButton : true) && /*#__PURE__*/React.createElement("li", {
2651
+ className: "list-inline-item"
2652
+ }, /*#__PURE__*/React.createElement("a", {
2647
2653
  href: "#",
2648
2654
  className: "btn btn-warning btn-clear",
2649
2655
  onClick: handleClear
@@ -3516,7 +3522,7 @@ var Form = /*#__PURE__*/function (_Component) {
3516
3522
  if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(props.validator, rootSchema)) {
3517
3523
  schemaUtils = createSchemaUtils(props.validator, rootSchema);
3518
3524
  }
3519
- var formData = schemaUtils.getDefaultFormState(schema, inputFormData, "excludeObjectChildren");
3525
+ var formData = schemaUtils.getDefaultFormState(schema, inputFormData);
3520
3526
  var retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
3521
3527
  var getCurrentErrors = function getCurrentErrors() {
3522
3528
  if (props.noValidate) {
@@ -3656,15 +3662,47 @@ var Form = /*#__PURE__*/function (_Component) {
3656
3662
  this.formElement.current.requestSubmit();
3657
3663
  }
3658
3664
  }
3665
+ /** Attempts to focus on the field associated with the `error`. Uses the `property` field to compute path of the error
3666
+ * field, then, using the `idPrefix` and `idSeparator` converts that path into an id. Then the input element with that
3667
+ * id is attempted to be found using the `formElement` ref. If it is located, then it is focused.
3668
+ *
3669
+ * @param error - The error on which to focus
3670
+ */;
3671
+ _proto.focusOnError = function focusOnError(error) {
3672
+ var _this$props4 = this.props,
3673
+ _this$props4$idPrefix = _this$props4.idPrefix,
3674
+ idPrefix = _this$props4$idPrefix === void 0 ? "root" : _this$props4$idPrefix,
3675
+ _this$props4$idSepara = _this$props4.idSeparator,
3676
+ idSeparator = _this$props4$idSepara === void 0 ? "_" : _this$props4$idSepara;
3677
+ var property = error.property;
3678
+ var path = _toPath(property);
3679
+ if (path[0] === "") {
3680
+ // Most of the time the `.foo` property results in the first element being empty, so replace it with the idPrefix
3681
+ path[0] = idPrefix;
3682
+ } else {
3683
+ // Otherwise insert the idPrefix into the first location using unshift
3684
+ path.unshift(idPrefix);
3685
+ }
3686
+ var elementId = path.join(idSeparator);
3687
+ var field = this.formElement.current.elements[elementId];
3688
+ if (!field) {
3689
+ // if not an exact match, try finding an input starting with the element id (like radio buttons or checkboxes)
3690
+ field = this.formElement.current.querySelector("input[id^=" + elementId);
3691
+ }
3692
+ if (field) {
3693
+ field.focus();
3694
+ }
3695
+ }
3659
3696
  /** Programmatically validate the form. If `onError` is provided, then it will be called with the list of errors the
3660
3697
  * same way as would happen on form submission.
3661
3698
  *
3662
3699
  * @returns - True if the form is valid, false otherwise.
3663
3700
  */;
3664
3701
  _proto.validateForm = function validateForm() {
3665
- var _this$props4 = this.props,
3666
- extraErrors = _this$props4.extraErrors,
3667
- onError = _this$props4.onError;
3702
+ var _this$props5 = this.props,
3703
+ extraErrors = _this$props5.extraErrors,
3704
+ focusOnFirstError = _this$props5.focusOnFirstError,
3705
+ onError = _this$props5.onError;
3668
3706
  var formData = this.state.formData;
3669
3707
  var schemaUtils = this.state.schemaUtils;
3670
3708
  var schemaValidation = this.validate(formData);
@@ -3678,6 +3716,9 @@ var Form = /*#__PURE__*/function (_Component) {
3678
3716
  errorSchema = merged.errorSchema;
3679
3717
  errors = merged.errors;
3680
3718
  }
3719
+ if (focusOnFirstError) {
3720
+ this.focusOnError(schemaValidation.errors[0]);
3721
+ }
3681
3722
  this.setState({
3682
3723
  errors: errors,
3683
3724
  errorSchema: errorSchema,
@@ -3698,31 +3739,31 @@ var Form = /*#__PURE__*/function (_Component) {
3698
3739
  * needed along with the submit button or any children of the form.
3699
3740
  */;
3700
3741
  _proto.render = function render() {
3701
- var _this$props5 = this.props,
3702
- children = _this$props5.children,
3703
- id = _this$props5.id,
3704
- idPrefix = _this$props5.idPrefix,
3705
- idSeparator = _this$props5.idSeparator,
3706
- _this$props5$classNam = _this$props5.className,
3707
- className = _this$props5$classNam === void 0 ? "" : _this$props5$classNam,
3708
- tagName = _this$props5.tagName,
3709
- name = _this$props5.name,
3710
- method = _this$props5.method,
3711
- target = _this$props5.target,
3712
- action = _this$props5.action,
3713
- autoComplete = _this$props5.autoComplete,
3714
- enctype = _this$props5.enctype,
3715
- acceptcharset = _this$props5.acceptcharset,
3716
- _this$props5$noHtml5V = _this$props5.noHtml5Validate,
3717
- noHtml5Validate = _this$props5$noHtml5V === void 0 ? false : _this$props5$noHtml5V,
3718
- _this$props5$disabled = _this$props5.disabled,
3719
- disabled = _this$props5$disabled === void 0 ? false : _this$props5$disabled,
3720
- _this$props5$readonly = _this$props5.readonly,
3721
- readonly = _this$props5$readonly === void 0 ? false : _this$props5$readonly,
3722
- formContext = _this$props5.formContext,
3723
- _this$props5$showErro = _this$props5.showErrorList,
3724
- showErrorList = _this$props5$showErro === void 0 ? "top" : _this$props5$showErro,
3725
- _internalFormWrapper = _this$props5._internalFormWrapper;
3742
+ var _this$props6 = this.props,
3743
+ children = _this$props6.children,
3744
+ id = _this$props6.id,
3745
+ idPrefix = _this$props6.idPrefix,
3746
+ idSeparator = _this$props6.idSeparator,
3747
+ _this$props6$classNam = _this$props6.className,
3748
+ className = _this$props6$classNam === void 0 ? "" : _this$props6$classNam,
3749
+ tagName = _this$props6.tagName,
3750
+ name = _this$props6.name,
3751
+ method = _this$props6.method,
3752
+ target = _this$props6.target,
3753
+ action = _this$props6.action,
3754
+ autoComplete = _this$props6.autoComplete,
3755
+ enctype = _this$props6.enctype,
3756
+ acceptcharset = _this$props6.acceptcharset,
3757
+ _this$props6$noHtml5V = _this$props6.noHtml5Validate,
3758
+ noHtml5Validate = _this$props6$noHtml5V === void 0 ? false : _this$props6$noHtml5V,
3759
+ _this$props6$disabled = _this$props6.disabled,
3760
+ disabled = _this$props6$disabled === void 0 ? false : _this$props6$disabled,
3761
+ _this$props6$readonly = _this$props6.readonly,
3762
+ readonly = _this$props6$readonly === void 0 ? false : _this$props6$readonly,
3763
+ formContext = _this$props6.formContext,
3764
+ _this$props6$showErro = _this$props6.showErrorList,
3765
+ showErrorList = _this$props6$showErro === void 0 ? "top" : _this$props6$showErro,
3766
+ _internalFormWrapper = _this$props6._internalFormWrapper;
3726
3767
  var _this$state4 = this.state,
3727
3768
  schema = _this$state4.schema,
3728
3769
  uiSchema = _this$state4.uiSchema,