@react-typed-forms/schemas 16.0.0 → 16.0.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.
package/lib/index.cjs CHANGED
@@ -631,6 +631,9 @@ function getNullToggler(c) {
631
631
  c.value = currentNotNull ? lastDefined.current.value : null;
632
632
  c.disabled = !currentNotNull;
633
633
  }, core.ControlChange.Value);
634
+ c.subscribe(function () {
635
+ notNull.value = c.current.value != null;
636
+ }, core.ControlChange.Value);
634
637
  return notNull;
635
638
  function disableIfNotEditing() {
636
639
  notNull.disabled = isEditing.current.value === false;
@@ -670,6 +673,22 @@ function getAllValues(control) {
670
673
  return core.newControl([control.value]);
671
674
  });
672
675
  }
676
+ function clearMultiValues(dataNode) {
677
+ var c = dataNode.control;
678
+ var sf = dataNode.schema.field;
679
+ if (sf.collection) {
680
+ return;
681
+ } else if (formsCore.isCompoundField(sf)) {
682
+ dataNode.schema.getChildNodes().forEach(function (c) {
683
+ clearMultiValues(dataNode.getChild(c));
684
+ });
685
+ } else {
686
+ var allValues = getAllValues(c);
687
+ allValues.setValue(function (x) {
688
+ return [c.current.value];
689
+ });
690
+ }
691
+ }
673
692
  function applyValues(dataNode, value) {
674
693
  var c = dataNode.control;
675
694
  var sf = dataNode.schema.field;
@@ -692,7 +711,10 @@ function applyValues(dataNode, value) {
692
711
  }
693
712
  function collectDifferences(dataNode, values) {
694
713
  values.forEach(function (v, i) {
695
- if (i == 0) dataNode.control.setInitialValue(v);else applyValues(dataNode, v);
714
+ if (i == 0) {
715
+ dataNode.control.setInitialValue(v);
716
+ clearMultiValues(dataNode);
717
+ } else applyValues(dataNode, v);
696
718
  });
697
719
  var allEdits = [];
698
720
  resetMultiValues(dataNode);
@@ -1590,7 +1612,10 @@ function RenderForm(_ref) {
1590
1612
  }),
1591
1613
  formState = _useState[0],
1592
1614
  setFormState = _useState[1];
1593
- var state = formState.getControlState(data, form, options);
1615
+ var effects = [];
1616
+ var state = formState.getControlState(data, form, options, function (cb) {
1617
+ return effects.push(cb);
1618
+ });
1594
1619
  react.useEffect(function () {
1595
1620
  if (!(options != null && options.formState)) {
1596
1621
  return function () {
@@ -1677,7 +1702,9 @@ function RenderForm(_ref) {
1677
1702
  textClass: textClass,
1678
1703
  getChildState: function getChildState(child, parent) {
1679
1704
  var _ref4;
1680
- return formState.getControlState((_ref4 = parent != null ? parent : state.dataNode) != null ? _ref4 : data, child, childOptions);
1705
+ return formState.getControlState((_ref4 = parent != null ? parent : state.dataNode) != null ? _ref4 : data, child, childOptions, function (cb) {
1706
+ return effects.push(cb);
1707
+ });
1681
1708
  },
1682
1709
  runExpression: function runExpression(scope, expr, returnResult) {
1683
1710
  if (expr != null && expr.type) {
@@ -1685,7 +1712,10 @@ function RenderForm(_ref) {
1685
1712
  scope: scope,
1686
1713
  dataNode: data,
1687
1714
  schemaInterface: schemaInterface,
1688
- returnResult: returnResult
1715
+ returnResult: returnResult,
1716
+ runAsync: function runAsync(cb) {
1717
+ return effects.push(cb);
1718
+ }
1689
1719
  });
1690
1720
  }
1691
1721
  }
@@ -1696,9 +1726,15 @@ function RenderForm(_ref) {
1696
1726
  style: state.layoutStyle
1697
1727
  });
1698
1728
  var renderedControl = renderer.renderLayout((_options$adjustLayout = options.adjustLayout == null ? void 0 : options.adjustLayout(dataContext, layoutProps)) != null ? _options$adjustLayout : layoutProps);
1699
- return renderer.renderVisibility(_extends({
1729
+ var rendered = renderer.renderVisibility(_extends({
1700
1730
  visibility: visibility
1701
1731
  }, renderedControl));
1732
+ react.useEffect(function () {
1733
+ effects.forEach(function (cb) {
1734
+ return cb();
1735
+ });
1736
+ }, [effects]);
1737
+ return rendered;
1702
1738
  } finally {
1703
1739
  _effect();
1704
1740
  }
@@ -1815,6 +1851,7 @@ exports.applyValues = applyValues;
1815
1851
  exports.autocompleteOptions = autocompleteOptions;
1816
1852
  exports.checkListOptions = checkListOptions;
1817
1853
  exports.cleanDataForSchema = cleanDataForSchema;
1854
+ exports.clearMultiValues = clearMultiValues;
1818
1855
  exports.coerceToString = coerceToString;
1819
1856
  exports.collectDifferences = collectDifferences;
1820
1857
  exports.compoundControl = compoundControl;