@planeasyinc/le-angular 0.0.17 → 0.0.19

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.
@@ -1725,12 +1725,27 @@ const traverse = (entity, path, cb) => {
1725
1725
  const isTabJSON = (control) => {
1726
1726
  return control.name.toLowerCase().includes('json');
1727
1727
  };
1728
- const getTabFormValues = (control, engine) => {
1728
+ /**
1729
+ *
1730
+ * @param source Control Config
1731
+ * @param target Control Config
1732
+ * @param engine Form Engine
1733
+ *
1734
+ * @description traverse source control tree, get latest value from state,
1735
+ * if no value found in state, set target control initial value
1736
+ */
1737
+ const getTabFormValues = (source, target, engine) => {
1729
1738
  const result = {};
1730
- traverse(control, ['meta', 'controls'], (ctrl) => {
1731
- if (ctrl.id && ctrl.value) {
1732
- result[ctrl.id] = engine.values.get(ctrl.id);
1739
+ const targetValueObject = mapJSONToFormValues(target.value);
1740
+ traverse(source, ['meta', 'controls'], (ctrl) => {
1741
+ if (!ctrl.id) {
1742
+ return;
1733
1743
  }
1744
+ const value = engine.values.get(ctrl.id) ?? targetValueObject[ctrl.id];
1745
+ if (value === undefined) {
1746
+ return;
1747
+ }
1748
+ result[ctrl.id] = value;
1734
1749
  });
1735
1750
  return result;
1736
1751
  };
@@ -1738,7 +1753,10 @@ const mapFormValuesToJSON = (values) => {
1738
1753
  return JSON.stringify(values, null, 2);
1739
1754
  };
1740
1755
  const mapJSONToFormValues = (json) => {
1741
- return JSON.parse(json);
1756
+ if (typeof json === 'string') {
1757
+ return JSON.parse(json);
1758
+ }
1759
+ throw new Error('The `json` parameter is not a valid JSON');
1742
1760
  };
1743
1761
  const getTabJSONControl = (control, engine) => {
1744
1762
  let result;
@@ -2116,8 +2134,8 @@ class FormViewComponent {
2116
2134
  });
2117
2135
  }
2118
2136
  else {
2119
- const value = mapFormValuesToJSON(getTabFormValues(action.source, engine));
2120
2137
  const target = getTabJSONControl(action.target, engine);
2138
+ const value = mapFormValuesToJSON(getTabFormValues(action.source, target, engine));
2121
2139
  engine.values.set(target.id, value);
2122
2140
  }
2123
2141
  }