@planeasyinc/le-angular 0.0.18 → 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,13 +1725,23 @@ 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) => {
1739
+ const targetValueObject = mapJSONToFormValues(target.value);
1740
+ traverse(source, ['meta', 'controls'], (ctrl) => {
1731
1741
  if (!ctrl.id) {
1732
1742
  return;
1733
1743
  }
1734
- const value = engine.values.get(ctrl.id);
1744
+ const value = engine.values.get(ctrl.id) ?? targetValueObject[ctrl.id];
1735
1745
  if (value === undefined) {
1736
1746
  return;
1737
1747
  }
@@ -1743,7 +1753,10 @@ const mapFormValuesToJSON = (values) => {
1743
1753
  return JSON.stringify(values, null, 2);
1744
1754
  };
1745
1755
  const mapJSONToFormValues = (json) => {
1746
- 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');
1747
1760
  };
1748
1761
  const getTabJSONControl = (control, engine) => {
1749
1762
  let result;
@@ -2121,8 +2134,8 @@ class FormViewComponent {
2121
2134
  });
2122
2135
  }
2123
2136
  else {
2124
- const value = mapFormValuesToJSON(getTabFormValues(action.source, engine));
2125
2137
  const target = getTabJSONControl(action.target, engine);
2138
+ const value = mapFormValuesToJSON(getTabFormValues(action.source, target, engine));
2126
2139
  engine.values.set(target.id, value);
2127
2140
  }
2128
2141
  }