@reactables/forms 0.5.3-alpha.0 → 0.5.4-alpha.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.
@@ -1,5 +1,27 @@
1
1
  import { Form, BaseForm } from '../../Models/Controls';
2
2
  import { ControlRef } from '../../Models/ControlRef';
3
+ import { FormErrors } from '../../Models/FormErrors';
3
4
  export declare const mergePushControl: <T>(state: Form<T>, form: BaseForm<T>, controlRef: ControlRef) => {
5
+ [x: string]: import("../../Models/Controls").FormControl<unknown> | {
6
+ errors: {
7
+ [x: string]: boolean;
8
+ };
9
+ valid: boolean;
10
+ childrenValid: boolean;
11
+ pristineValue: unknown;
12
+ controlRef: ControlRef;
13
+ value: unknown;
14
+ dirty: boolean;
15
+ touched: boolean;
16
+ validatorErrors: FormErrors;
17
+ config: import("../..").AbstractControlConfig;
18
+ key: string;
19
+ asyncValidatorErrors: FormErrors;
20
+ asyncValidateInProgress: {
21
+ [key: string]: boolean;
22
+ [key: number]: boolean;
23
+ };
24
+ pending?: boolean;
25
+ };
4
26
  root?: import("../../Models/Controls").FormControl<unknown>;
5
27
  };
package/dist/index.js CHANGED
@@ -875,12 +875,9 @@ var mergePushControl = function (state, form, controlRef) {
875
875
  var ancestors = getAncestorControls(controlRef, state)
876
876
  .reverse()
877
877
  .reduce(function (acc, control, index, arr) {
878
- var _a, _b;
878
+ var _a;
879
879
  var formKey = getFormKey(control.controlRef);
880
880
  var errors = __assign(__assign({}, form[formKey].validatorErrors), control.asyncValidatorErrors);
881
- if (!control.childrenValid)
882
- // If the ancestor control's children were not valid, pushing an item won't change its valid status
883
- return __assign(__assign({}, acc), (_a = {}, _a[formKey] = __assign(__assign(__assign({}, control), form[formKey]), { errors: errors }), _a));
884
881
  var selfValid = !hasErrors(errors);
885
882
  var childrenValid = true;
886
883
  if (index === 0) {
@@ -889,9 +886,24 @@ var mergePushControl = function (state, form, controlRef) {
889
886
  mergedDescendants[getFormKey(controlRef.concat(newItemIndex))].valid;
890
887
  }
891
888
  else {
892
- childrenValid = control.childrenValid && arr[index - 1].valid;
889
+ if (Array.isArray(control.config.controls)) {
890
+ // If control is a FormArray
891
+ childrenValid = control.value.every(function (item, index) {
892
+ var formKey = getFormKey(control.controlRef.concat(index));
893
+ var valid = acc[formKey] === undefined ? state[formKey].valid : acc[formKey].valid;
894
+ return valid;
895
+ });
896
+ }
897
+ else if (control.config.controls) {
898
+ // If control is a FormGroup
899
+ childrenValid = Object.keys(control.value).every(function (childKey) {
900
+ var formKey = getFormKey(control.controlRef.concat(childKey));
901
+ var valid = acc[formKey] === undefined ? state[formKey].valid : acc[formKey].valid;
902
+ return valid;
903
+ });
904
+ }
893
905
  }
894
- return __assign(__assign({}, acc), (_b = {}, _b[formKey] = __assign(__assign(__assign({}, control), form[formKey]), { errors: errors, valid: selfValid && childrenValid, childrenValid: childrenValid }), _b));
906
+ return __assign(__assign({}, acc), (_a = {}, _a[formKey] = __assign(__assign(__assign({}, control), form[formKey]), { errors: errors, valid: selfValid && childrenValid, childrenValid: childrenValid }), _a));
895
907
  }, {});
896
908
  var controlBranchUpdated = __assign(__assign({}, ancestors), mergedDescendants);
897
909
  return __assign(__assign({}, state), controlBranchUpdated);
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "author": "David Lai",
15
15
  "license": "ISC",
16
16
  "dependencies": {
17
- "@reactables/core": "^0.5.3-alpha.0",
17
+ "@reactables/core": "^0.5.4-alpha.0",
18
18
  "lodash.isequal": "^4.5.0"
19
19
  },
20
20
  "peerDependencies": {
@@ -23,5 +23,5 @@
23
23
  "devDependencies": {
24
24
  "lodash.clonedeep": "^4.5.0"
25
25
  },
26
- "version": "0.5.3-alpha.0"
26
+ "version": "0.5.4-alpha.0"
27
27
  }