@react-typed-forms/schemas 11.2.1 → 11.3.2

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.
@@ -1,9 +1,10 @@
1
1
  import { RenderedLayout } from "../controlRender";
2
- import React from "react";
2
+ import React, { ReactNode } from "react";
3
3
  export interface DefaultLayoutRendererOptions {
4
4
  className?: string;
5
5
  errorClass?: string;
6
+ renderError?: (errorText: string | null | undefined) => ReactNode;
6
7
  }
7
- export declare function DefaultLayout({ errorClass, layout: { controlEnd, controlStart, label, children, errorControl }, }: DefaultLayoutRendererOptions & {
8
+ export declare function DefaultLayout({ errorClass, renderError, layout: { controlEnd, controlStart, label, children, errorControl }, }: DefaultLayoutRendererOptions & {
8
9
  layout: RenderedLayout;
9
10
  }): React.JSX.Element;
package/lib/index.js CHANGED
@@ -462,9 +462,10 @@ function visitControlData(definition, ctx, cb) {
462
462
  if (!fieldData) return !fieldName ? visitControlDataArray(children, ctx, cb) : undefined;
463
463
  var thisPath = [].concat(ctx.path, [fieldData.field]);
464
464
  var control = ctx.data.lookupControl(thisPath);
465
- if (!control) throw "No control for field";
465
+ if (!control) return undefined;
466
466
  var result = def ? cb(def, fieldData, control, false) : undefined;
467
467
  if (result !== undefined) return result;
468
+ var compound = isCompoundField(fieldData);
468
469
  if (fieldData.collection) {
469
470
  var cIndex = 0;
470
471
  for (var _iterator3 = _createForOfIteratorHelperLoose((_control$elements = control.elements) != null ? _control$elements : []), _step3; !(_step3 = _iterator3()).done;) {
@@ -472,7 +473,7 @@ function visitControlData(definition, ctx, cb) {
472
473
  var c = _step3.value;
473
474
  var elemResult = def ? cb(def, fieldData, c, true) : undefined;
474
475
  if (elemResult !== undefined) return elemResult;
475
- if (isCompoundField(fieldData)) {
476
+ if (compound) {
476
477
  var cfResult = visitControlDataArray(children, _extends({}, ctx, {
477
478
  fields: fieldData.children,
478
479
  path: [].concat(thisPath, [cIndex])
@@ -481,7 +482,13 @@ function visitControlData(definition, ctx, cb) {
481
482
  }
482
483
  cIndex++;
483
484
  }
485
+ } else if (compound) {
486
+ return visitControlDataArray(children, _extends({}, ctx, {
487
+ fields: fieldData.children,
488
+ path: thisPath
489
+ }), cb);
484
490
  }
491
+ return undefined;
485
492
  }
486
493
  }
487
494
  function lookupChildControl(data, path) {
@@ -1935,6 +1942,12 @@ function DefaultLayout(_ref) {
1935
1942
  var _effect = core.useComponentTracking();
1936
1943
  try {
1937
1944
  var errorClass = _ref.errorClass,
1945
+ _ref$renderError = _ref.renderError,
1946
+ renderError = _ref$renderError === void 0 ? function (e) {
1947
+ return e && /*#__PURE__*/React__default["default"].createElement("div", {
1948
+ className: errorClass
1949
+ }, e);
1950
+ } : _ref$renderError,
1938
1951
  _ref$layout = _ref.layout,
1939
1952
  controlEnd = _ref$layout.controlEnd,
1940
1953
  controlStart = _ref$layout.controlStart,
@@ -1943,9 +1956,7 @@ function DefaultLayout(_ref) {
1943
1956
  errorControl = _ref$layout.errorControl;
1944
1957
  var ec = errorControl;
1945
1958
  var errorText = ec && ec.touched ? ec.error : undefined;
1946
- return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, label, controlStart, children, errorText && /*#__PURE__*/React__default["default"].createElement("div", {
1947
- className: errorClass
1948
- }, errorText), controlEnd);
1959
+ return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, label, controlStart, children, renderError(errorText), controlEnd);
1949
1960
  } finally {
1950
1961
  _effect();
1951
1962
  }