@rolster/forms 3.2.1 → 3.3.1
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/dist/cjs/helpers.js +84 -31
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/index.js +81 -79
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/helpers.js +75 -25
- package/dist/es/helpers.js.map +1 -1
- package/dist/es/index.js +81 -79
- package/dist/es/index.js.map +1 -1
- package/dist/esm/form-array/form-array-control.d.ts +3 -3
- package/dist/esm/form-array/form-array-control.js +2 -2
- package/dist/esm/form-array/form-array-control.js.map +1 -1
- package/dist/esm/form-array/form-array-control.type.d.ts +11 -0
- package/dist/esm/form-array/form-array-control.type.js +2 -0
- package/dist/esm/form-array/form-array-control.type.js.map +1 -0
- package/dist/esm/form-array/form-array-group.d.ts +4 -4
- package/dist/esm/form-array/form-array-group.js +2 -2
- package/dist/esm/form-array/form-array-group.js.map +1 -1
- package/dist/esm/form-array/form-array-group.type.d.ts +20 -0
- package/dist/esm/form-array/form-array-group.type.js +2 -0
- package/dist/esm/form-array/form-array-group.type.js.map +1 -0
- package/dist/esm/form-array/form-array-list.d.ts +3 -3
- package/dist/esm/form-array/form-array-list.js +8 -8
- package/dist/esm/form-array/form-array-list.js.map +1 -1
- package/dist/esm/form-array/form-array-list.type.d.ts +8 -0
- package/dist/esm/form-array/form-array-list.type.js +2 -0
- package/dist/esm/form-array/form-array-list.type.js.map +1 -0
- package/dist/esm/form-array/form-array.d.ts +14 -14
- package/dist/esm/form-array/form-array.helper.d.ts +17 -0
- package/dist/esm/form-array/form-array.helper.js +34 -0
- package/dist/esm/form-array/form-array.helper.js.map +1 -0
- package/dist/esm/form-array/form-array.js +14 -14
- package/dist/esm/form-array/form-array.js.map +1 -1
- package/dist/esm/form-array/form-array.type.d.ts +34 -0
- package/dist/esm/form-array/form-array.type.js +2 -0
- package/dist/esm/form-array/form-array.type.js.map +1 -0
- package/dist/esm/{form-control.d.ts → form-control/form-control.d.ts} +2 -2
- package/dist/esm/form-control/form-control.helper.d.ts +13 -0
- package/dist/esm/form-control/form-control.helper.js +27 -0
- package/dist/esm/form-control/form-control.helper.js.map +1 -0
- package/dist/esm/{form-control.js → form-control/form-control.js} +3 -3
- package/dist/esm/form-control/form-control.js.map +1 -0
- package/dist/esm/form-control/form-control.type.d.ts +41 -0
- package/dist/esm/form-control/form-control.type.js +2 -0
- package/dist/esm/form-control/form-control.type.js.map +1 -0
- package/dist/esm/{form-group.d.ts → form-group/form-group.d.ts} +4 -3
- package/dist/esm/form-group/form-group.helper.d.ts +17 -0
- package/dist/esm/form-group/form-group.helper.js +36 -0
- package/dist/esm/form-group/form-group.helper.js.map +1 -0
- package/dist/esm/{form-group.js → form-group/form-group.js} +7 -8
- package/dist/esm/form-group/form-group.js.map +1 -0
- package/dist/esm/form-group/form-group.type.d.ts +36 -0
- package/dist/esm/form-group/form-group.type.js +2 -0
- package/dist/esm/form-group/form-group.type.js.map +1 -0
- package/dist/esm/helpers.d.ts +6 -23
- package/dist/esm/helpers.js +3 -46
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/index.d.ts +12 -4
- package/dist/esm/index.js +12 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -10
- package/arguments/package.json +0 -18
- package/dist/cjs/arguments.js +0 -54
- package/dist/cjs/arguments.js.map +0 -1
- package/dist/es/arguments.js +0 -50
- package/dist/es/arguments.js.map +0 -1
- package/dist/esm/arguments.d.ts +0 -18
- package/dist/esm/arguments.js +0 -48
- package/dist/esm/arguments.js.map +0 -1
- package/dist/esm/form-array/arguments.d.ts +0 -6
- package/dist/esm/form-array/arguments.js +0 -2
- package/dist/esm/form-array/arguments.js.map +0 -1
- package/dist/esm/form-array/index.d.ts +0 -5
- package/dist/esm/form-array/index.js +0 -6
- package/dist/esm/form-array/index.js.map +0 -1
- package/dist/esm/form-array/types.d.ts +0 -2
- package/dist/esm/form-array/types.js +0 -2
- package/dist/esm/form-array/types.js.map +0 -1
- package/dist/esm/form-control.js.map +0 -1
- package/dist/esm/form-group.js.map +0 -1
- package/dist/esm/types.d.ts +0 -143
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
package/dist/cjs/helpers.js
CHANGED
|
@@ -2,54 +2,104 @@
|
|
|
2
2
|
|
|
3
3
|
var commons = require('@rolster/commons');
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
return
|
|
5
|
+
function valueIsArrayOptions(options) {
|
|
6
|
+
return (typeof options === 'object' &&
|
|
7
|
+
('groups' in options || 'validators' in options));
|
|
8
|
+
}
|
|
9
|
+
function createFormArrayOptions(...argsOptions) {
|
|
10
|
+
const [options, validators] = argsOptions;
|
|
11
|
+
if (!options) {
|
|
12
|
+
return { groups: options, validators };
|
|
13
|
+
}
|
|
14
|
+
if (!validators && valueIsArrayOptions(options)) {
|
|
15
|
+
return options;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
groups: options,
|
|
19
|
+
validators
|
|
20
|
+
};
|
|
7
21
|
}
|
|
8
|
-
const
|
|
22
|
+
const formArrayIsValid = ({ groups, validators }) => {
|
|
9
23
|
return validators.reduce((errors, validator) => {
|
|
10
|
-
const error = validator(
|
|
24
|
+
const error = validator(groups);
|
|
11
25
|
if (error) {
|
|
12
26
|
errors.push(error);
|
|
13
27
|
}
|
|
14
28
|
return errors;
|
|
15
29
|
}, []);
|
|
16
30
|
};
|
|
17
|
-
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
31
|
+
function verifyAllTrueInGroups(groups, key) {
|
|
32
|
+
return groups.reduce((value, group) => value && commons.parseBoolean(group[key]), true);
|
|
33
|
+
}
|
|
34
|
+
function verifyAnyTrueInGroups(groups, key) {
|
|
35
|
+
return groups.reduce((value, group) => value || commons.parseBoolean(group[key]), false);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function valueIsControlOptions(options) {
|
|
39
|
+
return (typeof options === 'object' &&
|
|
40
|
+
('value' in options || 'validators' in options));
|
|
41
|
+
}
|
|
42
|
+
function createFormControlOptions(...argsOptions) {
|
|
43
|
+
const [options, validators] = argsOptions;
|
|
44
|
+
if (!options) {
|
|
45
|
+
return { value: options, validators };
|
|
46
|
+
}
|
|
47
|
+
if (!validators && valueIsControlOptions(options)) {
|
|
48
|
+
return options;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
value: options,
|
|
52
|
+
validators
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const formControlIsValid = ({ value, validators }) => {
|
|
30
56
|
return validators.reduce((errors, validator) => {
|
|
31
|
-
const error = validator(
|
|
57
|
+
const error = validator(value);
|
|
32
58
|
if (error) {
|
|
33
59
|
errors.push(error);
|
|
34
60
|
}
|
|
35
61
|
return errors;
|
|
36
62
|
}, []);
|
|
37
63
|
};
|
|
38
|
-
|
|
39
|
-
|
|
64
|
+
|
|
65
|
+
function valueIsGroupOptions(options) {
|
|
66
|
+
return typeof options === 'object' && 'controls' in options;
|
|
40
67
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
68
|
+
function createFormGroupOptions(...argsOptions) {
|
|
69
|
+
const [options, validators] = argsOptions;
|
|
70
|
+
if (!validators && valueIsGroupOptions(options)) {
|
|
71
|
+
return options;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
controls: options,
|
|
75
|
+
validators
|
|
76
|
+
};
|
|
43
77
|
}
|
|
44
|
-
const
|
|
78
|
+
const formGroupIsValid = ({ controls, validators }) => {
|
|
45
79
|
return validators.reduce((errors, validator) => {
|
|
46
|
-
const error = validator(
|
|
80
|
+
const error = validator(controls);
|
|
47
81
|
if (error) {
|
|
48
82
|
errors.push(error);
|
|
49
83
|
}
|
|
50
84
|
return errors;
|
|
51
85
|
}, []);
|
|
52
86
|
};
|
|
87
|
+
const controlsToValue = (controls) => {
|
|
88
|
+
return Object.entries(controls).reduce((result, [key, { value }]) => {
|
|
89
|
+
result[key] = value;
|
|
90
|
+
return result;
|
|
91
|
+
}, {});
|
|
92
|
+
};
|
|
93
|
+
const verifyAllTrueInControls = (controls, key) => {
|
|
94
|
+
return Object.values(controls).reduce((value, control) => control.disabled ? value : value && commons.parseBoolean(control[key]), true);
|
|
95
|
+
};
|
|
96
|
+
const verifyAnyTrueInControls = (controls, key) => {
|
|
97
|
+
return Object.values(controls).reduce((value, control) => control.disabled ? value : value || commons.parseBoolean(control[key]), false);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
function reduceErrors(errors) {
|
|
101
|
+
return errors.reduce((keys, { id }) => [...keys, id], []);
|
|
102
|
+
}
|
|
53
103
|
function hasError(errors, key) {
|
|
54
104
|
return reduceErrors(errors).includes(key);
|
|
55
105
|
}
|
|
@@ -63,16 +113,19 @@ function reduceGroupToArray(group, key) {
|
|
|
63
113
|
return reduceControlsToArray(group.controls, key);
|
|
64
114
|
}
|
|
65
115
|
|
|
66
|
-
exports.arrayIsValid = arrayIsValid;
|
|
67
|
-
exports.controlIsValid = controlIsValid;
|
|
68
|
-
exports.controlsAllChecked = controlsAllChecked;
|
|
69
|
-
exports.controlsPartialChecked = controlsPartialChecked;
|
|
70
116
|
exports.controlsToValue = controlsToValue;
|
|
71
|
-
exports.
|
|
72
|
-
exports.
|
|
73
|
-
exports.
|
|
117
|
+
exports.createFormArrayOptions = createFormArrayOptions;
|
|
118
|
+
exports.createFormControlOptions = createFormControlOptions;
|
|
119
|
+
exports.createFormGroupOptions = createFormGroupOptions;
|
|
120
|
+
exports.formArrayIsValid = formArrayIsValid;
|
|
121
|
+
exports.formControlIsValid = formControlIsValid;
|
|
122
|
+
exports.formGroupIsValid = formGroupIsValid;
|
|
74
123
|
exports.hasError = hasError;
|
|
75
124
|
exports.reduceControlsToArray = reduceControlsToArray;
|
|
76
125
|
exports.reduceGroupToArray = reduceGroupToArray;
|
|
77
126
|
exports.someErrors = someErrors;
|
|
127
|
+
exports.verifyAllTrueInControls = verifyAllTrueInControls;
|
|
128
|
+
exports.verifyAllTrueInGroups = verifyAllTrueInGroups;
|
|
129
|
+
exports.verifyAnyTrueInControls = verifyAnyTrueInControls;
|
|
130
|
+
exports.verifyAnyTrueInGroups = verifyAnyTrueInGroups;
|
|
78
131
|
//# sourceMappingURL=helpers.js.map
|
package/dist/cjs/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sources":["../esm/helpers.js"],"sourcesContent":["import { parseBoolean } from '@rolster/commons';\nfunction
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../esm/form-array/form-array.helper.js","../esm/form-control/form-control.helper.js","../esm/form-group/form-group.helper.js","../esm/helpers.js"],"sourcesContent":["import { parseBoolean } from '@rolster/commons';\nfunction valueIsArrayOptions(options) {\n return (typeof options === 'object' &&\n ('groups' in options || 'validators' in options));\n}\nexport function createFormArrayOptions(...argsOptions) {\n const [options, validators] = argsOptions;\n if (!options) {\n return { groups: options, validators };\n }\n if (!validators && valueIsArrayOptions(options)) {\n return options;\n }\n return {\n groups: options,\n validators\n };\n}\nexport const formArrayIsValid = ({ groups, validators }) => {\n return validators.reduce((errors, validator) => {\n const error = validator(groups);\n if (error) {\n errors.push(error);\n }\n return errors;\n }, []);\n};\nexport function verifyAllTrueInGroups(groups, key) {\n return groups.reduce((value, group) => value && parseBoolean(group[key]), true);\n}\nexport function verifyAnyTrueInGroups(groups, key) {\n return groups.reduce((value, group) => value || parseBoolean(group[key]), false);\n}\n//# sourceMappingURL=form-array.helper.js.map","function valueIsControlOptions(options) {\n return (typeof options === 'object' &&\n ('value' in options || 'validators' in options));\n}\nexport function createFormControlOptions(...argsOptions) {\n const [options, validators] = argsOptions;\n if (!options) {\n return { value: options, validators };\n }\n if (!validators && valueIsControlOptions(options)) {\n return options;\n }\n return {\n value: options,\n validators\n };\n}\nexport const formControlIsValid = ({ value, validators }) => {\n return validators.reduce((errors, validator) => {\n const error = validator(value);\n if (error) {\n errors.push(error);\n }\n return errors;\n }, []);\n};\n//# sourceMappingURL=form-control.helper.js.map","import { parseBoolean } from '@rolster/commons';\nfunction valueIsGroupOptions(options) {\n return typeof options === 'object' && 'controls' in options;\n}\nexport function createFormGroupOptions(...argsOptions) {\n const [options, validators] = argsOptions;\n if (!validators && valueIsGroupOptions(options)) {\n return options;\n }\n return {\n controls: options,\n validators\n };\n}\nexport const formGroupIsValid = ({ controls, validators }) => {\n return validators.reduce((errors, validator) => {\n const error = validator(controls);\n if (error) {\n errors.push(error);\n }\n return errors;\n }, []);\n};\nexport const controlsToValue = (controls) => {\n return Object.entries(controls).reduce((result, [key, { value }]) => {\n result[key] = value;\n return result;\n }, {});\n};\nexport const verifyAllTrueInControls = (controls, key) => {\n return Object.values(controls).reduce((value, control) => control.disabled ? value : value && parseBoolean(control[key]), true);\n};\nexport const verifyAnyTrueInControls = (controls, key) => {\n return Object.values(controls).reduce((value, control) => control.disabled ? value : value || parseBoolean(control[key]), false);\n};\n//# sourceMappingURL=form-group.helper.js.map","function reduceErrors(errors) {\n return errors.reduce((keys, { id }) => [...keys, id], []);\n}\nexport function hasError(errors, key) {\n return reduceErrors(errors).includes(key);\n}\nexport function someErrors(errors, keys) {\n return reduceErrors(errors).some((key) => keys.includes(key));\n}\nexport function reduceControlsToArray(controls, key) {\n return Object.values(controls).map((control) => control[key]);\n}\nexport function reduceGroupToArray(group, key) {\n return reduceControlsToArray(group.controls, key);\n}\nexport * from './form-array/form-array.helper';\nexport * from './form-control/form-control.helper';\nexport * from './form-group/form-group.helper';\n//# sourceMappingURL=helpers.js.map"],"names":["parseBoolean"],"mappings":";;;;AACA,SAAS,mBAAmB,CAAC,OAAO,EAAE;AACtC,IAAI,QAAQ,OAAO,OAAO,KAAK,QAAQ;AACvC,SAAS,QAAQ,IAAI,OAAO,IAAI,YAAY,IAAI,OAAO,CAAC,EAAE;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
|
-
function
|
|
6
|
+
function valueIsControlOptions(options) {
|
|
7
7
|
return (typeof options === 'object' &&
|
|
8
8
|
('value' in options || 'validators' in options));
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
function arrayIsOptions(options) {
|
|
14
|
-
return (typeof options === 'object' &&
|
|
15
|
-
('groups' in options || 'validators' in options));
|
|
16
|
-
}
|
|
17
|
-
function createFormControlOptions(...controlOptions) {
|
|
18
|
-
const [options, validators] = controlOptions;
|
|
10
|
+
function createFormControlOptions(...argsOptions) {
|
|
11
|
+
const [options, validators] = argsOptions;
|
|
19
12
|
if (!options) {
|
|
20
13
|
return { value: options, validators };
|
|
21
14
|
}
|
|
22
|
-
if (!validators &&
|
|
15
|
+
if (!validators && valueIsControlOptions(options)) {
|
|
23
16
|
return options;
|
|
24
17
|
}
|
|
25
18
|
return {
|
|
@@ -27,22 +20,26 @@ function createFormControlOptions(...controlOptions) {
|
|
|
27
20
|
validators
|
|
28
21
|
};
|
|
29
22
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
const formControlIsValid = ({ value, validators }) => {
|
|
24
|
+
return validators.reduce((errors, validator) => {
|
|
25
|
+
const error = validator(value);
|
|
26
|
+
if (error) {
|
|
27
|
+
errors.push(error);
|
|
28
|
+
}
|
|
29
|
+
return errors;
|
|
30
|
+
}, []);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function valueIsArrayOptions(options) {
|
|
34
|
+
return (typeof options === 'object' &&
|
|
35
|
+
('groups' in options || 'validators' in options));
|
|
39
36
|
}
|
|
40
|
-
function createFormArrayOptions(...
|
|
41
|
-
const [options, validators] =
|
|
37
|
+
function createFormArrayOptions(...argsOptions) {
|
|
38
|
+
const [options, validators] = argsOptions;
|
|
42
39
|
if (!options) {
|
|
43
40
|
return { groups: options, validators };
|
|
44
41
|
}
|
|
45
|
-
if (!validators &&
|
|
42
|
+
if (!validators && valueIsArrayOptions(options)) {
|
|
46
43
|
return options;
|
|
47
44
|
}
|
|
48
45
|
return {
|
|
@@ -50,55 +47,60 @@ function createFormArrayOptions(...arrayOptions) {
|
|
|
50
47
|
validators
|
|
51
48
|
};
|
|
52
49
|
}
|
|
53
|
-
|
|
54
|
-
function reduceErrors(errors) {
|
|
55
|
-
return errors.reduce((keys, { id }) => [...keys, id], []);
|
|
56
|
-
}
|
|
57
|
-
const controlIsValid = ({ value, validators }) => {
|
|
58
|
-
return validators.reduce((errors, validator) => {
|
|
59
|
-
const error = validator(value);
|
|
60
|
-
if (error) {
|
|
61
|
-
errors.push(error);
|
|
62
|
-
}
|
|
63
|
-
return errors;
|
|
64
|
-
}, []);
|
|
65
|
-
};
|
|
66
|
-
const controlsAllChecked = (controls, key) => {
|
|
67
|
-
return Object.values(controls).reduce((value, control) => control.disabled ? value : value && commons.parseBoolean(control[key]), true);
|
|
68
|
-
};
|
|
69
|
-
const controlsPartialChecked = (controls, key) => {
|
|
70
|
-
return Object.values(controls).reduce((value, control) => control.disabled ? value : value || commons.parseBoolean(control[key]), false);
|
|
71
|
-
};
|
|
72
|
-
const controlsToValue = (controls) => {
|
|
73
|
-
return Object.entries(controls).reduce((result, [key, { value }]) => {
|
|
74
|
-
result[key] = value;
|
|
75
|
-
return result;
|
|
76
|
-
}, {});
|
|
77
|
-
};
|
|
78
|
-
const groupIsValid = ({ controls, validators }) => {
|
|
50
|
+
const formArrayIsValid = ({ groups, validators }) => {
|
|
79
51
|
return validators.reduce((errors, validator) => {
|
|
80
|
-
const error = validator(
|
|
52
|
+
const error = validator(groups);
|
|
81
53
|
if (error) {
|
|
82
54
|
errors.push(error);
|
|
83
55
|
}
|
|
84
56
|
return errors;
|
|
85
57
|
}, []);
|
|
86
58
|
};
|
|
87
|
-
function
|
|
59
|
+
function verifyAllTrueInGroups(groups, key) {
|
|
88
60
|
return groups.reduce((value, group) => value && commons.parseBoolean(group[key]), true);
|
|
89
61
|
}
|
|
90
|
-
function
|
|
62
|
+
function verifyAnyTrueInGroups(groups, key) {
|
|
91
63
|
return groups.reduce((value, group) => value || commons.parseBoolean(group[key]), false);
|
|
92
64
|
}
|
|
93
|
-
|
|
65
|
+
|
|
66
|
+
function valueIsGroupOptions(options) {
|
|
67
|
+
return typeof options === 'object' && 'controls' in options;
|
|
68
|
+
}
|
|
69
|
+
function createFormGroupOptions(...argsOptions) {
|
|
70
|
+
const [options, validators] = argsOptions;
|
|
71
|
+
if (!validators && valueIsGroupOptions(options)) {
|
|
72
|
+
return options;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
controls: options,
|
|
76
|
+
validators
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const formGroupIsValid = ({ controls, validators }) => {
|
|
94
80
|
return validators.reduce((errors, validator) => {
|
|
95
|
-
const error = validator(
|
|
81
|
+
const error = validator(controls);
|
|
96
82
|
if (error) {
|
|
97
83
|
errors.push(error);
|
|
98
84
|
}
|
|
99
85
|
return errors;
|
|
100
86
|
}, []);
|
|
101
87
|
};
|
|
88
|
+
const controlsToValue = (controls) => {
|
|
89
|
+
return Object.entries(controls).reduce((result, [key, { value }]) => {
|
|
90
|
+
result[key] = value;
|
|
91
|
+
return result;
|
|
92
|
+
}, {});
|
|
93
|
+
};
|
|
94
|
+
const verifyAllTrueInControls = (controls, key) => {
|
|
95
|
+
return Object.values(controls).reduce((value, control) => control.disabled ? value : value && commons.parseBoolean(control[key]), true);
|
|
96
|
+
};
|
|
97
|
+
const verifyAnyTrueInControls = (controls, key) => {
|
|
98
|
+
return Object.values(controls).reduce((value, control) => control.disabled ? value : value || commons.parseBoolean(control[key]), false);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
function reduceErrors(errors) {
|
|
102
|
+
return errors.reduce((keys, { id }) => [...keys, id], []);
|
|
103
|
+
}
|
|
102
104
|
function hasError(errors, key) {
|
|
103
105
|
return reduceErrors(errors).includes(key);
|
|
104
106
|
}
|
|
@@ -210,7 +212,7 @@ class FormControl {
|
|
|
210
212
|
}
|
|
211
213
|
updateValueAndValidity(value, validators) {
|
|
212
214
|
if (validators) {
|
|
213
|
-
const errors =
|
|
215
|
+
const errors = formControlIsValid({ value, validators });
|
|
214
216
|
this._error = errors[0];
|
|
215
217
|
this._errors = errors;
|
|
216
218
|
this._valid = errors.length === 0;
|
|
@@ -262,10 +264,10 @@ class FormGroup {
|
|
|
262
264
|
return this._controls;
|
|
263
265
|
}
|
|
264
266
|
get touched() {
|
|
265
|
-
return
|
|
267
|
+
return verifyAnyTrueInControls(this.controls, 'touched');
|
|
266
268
|
}
|
|
267
269
|
get toucheds() {
|
|
268
|
-
return
|
|
270
|
+
return verifyAllTrueInControls(this.controls, 'touched');
|
|
269
271
|
}
|
|
270
272
|
get untouched() {
|
|
271
273
|
return !this.touched;
|
|
@@ -274,10 +276,10 @@ class FormGroup {
|
|
|
274
276
|
return !this.toucheds;
|
|
275
277
|
}
|
|
276
278
|
get dirty() {
|
|
277
|
-
return
|
|
279
|
+
return verifyAnyTrueInControls(this.controls, 'dirty');
|
|
278
280
|
}
|
|
279
281
|
get dirties() {
|
|
280
|
-
return
|
|
282
|
+
return verifyAllTrueInControls(this.controls, 'dirty');
|
|
281
283
|
}
|
|
282
284
|
get pristine() {
|
|
283
285
|
return !this.dirty;
|
|
@@ -286,7 +288,7 @@ class FormGroup {
|
|
|
286
288
|
return this.dirties;
|
|
287
289
|
}
|
|
288
290
|
get valid() {
|
|
289
|
-
return this._valid &&
|
|
291
|
+
return this._valid && verifyAllTrueInControls(this.controls, 'valid');
|
|
290
292
|
}
|
|
291
293
|
get invalid() {
|
|
292
294
|
return !this.valid;
|
|
@@ -317,7 +319,7 @@ class FormGroup {
|
|
|
317
319
|
}
|
|
318
320
|
updateValueAndValidity(controls, validators) {
|
|
319
321
|
if (validators) {
|
|
320
|
-
const errors =
|
|
322
|
+
const errors = formGroupIsValid({ controls, validators });
|
|
321
323
|
this._errors = errors;
|
|
322
324
|
this._error = errors[0];
|
|
323
325
|
this._valid = errors.length === 0;
|
|
@@ -347,24 +349,24 @@ function formArrayGroup(options, validators) {
|
|
|
347
349
|
|
|
348
350
|
class FormArrayList extends FormControl {
|
|
349
351
|
constructor(valueToControls, value, validators) {
|
|
350
|
-
const
|
|
351
|
-
super(
|
|
352
|
+
const formValue = value || [];
|
|
353
|
+
super(formValue, validators);
|
|
352
354
|
this.valueToControls = valueToControls;
|
|
353
|
-
this._controls =
|
|
355
|
+
this._controls = formValue.map((value) => this.createControls(value));
|
|
354
356
|
this.uuid = uuid.v4();
|
|
355
357
|
}
|
|
356
358
|
get controls() {
|
|
357
359
|
return this._controls;
|
|
358
360
|
}
|
|
359
361
|
get touched() {
|
|
360
|
-
return this.controls.reduce((valid, controls) => valid &&
|
|
362
|
+
return this.controls.reduce((valid, controls) => valid && verifyAnyTrueInControls(controls, 'touched'), true);
|
|
361
363
|
}
|
|
362
364
|
get dirty() {
|
|
363
|
-
return this.controls.reduce((valid, controls) => valid &&
|
|
365
|
+
return this.controls.reduce((valid, controls) => valid && verifyAnyTrueInControls(controls, 'dirty'), true);
|
|
364
366
|
}
|
|
365
367
|
get valid() {
|
|
366
368
|
return (this._valid &&
|
|
367
|
-
this.controls.reduce((valid, controls) => valid &&
|
|
369
|
+
this.controls.reduce((valid, controls) => valid && verifyAllTrueInControls(controls, 'valid'), true));
|
|
368
370
|
}
|
|
369
371
|
get value() {
|
|
370
372
|
return this.controls.map((controls) => controlsToValue(controls));
|
|
@@ -401,7 +403,7 @@ class FormArray {
|
|
|
401
403
|
this._errors = [];
|
|
402
404
|
const formArray = createFormArrayOptions(options, validators);
|
|
403
405
|
this.unsusbcriptions = new Map();
|
|
404
|
-
this.
|
|
406
|
+
this.map = new Map();
|
|
405
407
|
this.defaultValue = formArray.groups;
|
|
406
408
|
this.validators = formArray.validators;
|
|
407
409
|
this.refresh(this.defaultValue);
|
|
@@ -417,10 +419,10 @@ class FormArray {
|
|
|
417
419
|
return this.groups.map(({ controls }) => controls);
|
|
418
420
|
}
|
|
419
421
|
get touched() {
|
|
420
|
-
return
|
|
422
|
+
return verifyAnyTrueInGroups(this.groups, 'touched');
|
|
421
423
|
}
|
|
422
424
|
get toucheds() {
|
|
423
|
-
return
|
|
425
|
+
return verifyAllTrueInGroups(this.groups, 'toucheds');
|
|
424
426
|
}
|
|
425
427
|
get untouched() {
|
|
426
428
|
return !this.touched;
|
|
@@ -429,10 +431,10 @@ class FormArray {
|
|
|
429
431
|
return !this.toucheds;
|
|
430
432
|
}
|
|
431
433
|
get dirty() {
|
|
432
|
-
return
|
|
434
|
+
return verifyAnyTrueInGroups(this.groups, 'dirty');
|
|
433
435
|
}
|
|
434
436
|
get dirties() {
|
|
435
|
-
return
|
|
437
|
+
return verifyAllTrueInGroups(this.groups, 'dirties');
|
|
436
438
|
}
|
|
437
439
|
get pristine() {
|
|
438
440
|
return !this.dirty;
|
|
@@ -447,7 +449,7 @@ class FormArray {
|
|
|
447
449
|
return !this._disabled;
|
|
448
450
|
}
|
|
449
451
|
get valid() {
|
|
450
|
-
return this._valid &&
|
|
452
|
+
return this._valid && verifyAllTrueInGroups(this.groups, 'valid');
|
|
451
453
|
}
|
|
452
454
|
get invalid() {
|
|
453
455
|
return !this._valid;
|
|
@@ -480,7 +482,7 @@ class FormArray {
|
|
|
480
482
|
this._disabled = false;
|
|
481
483
|
}
|
|
482
484
|
findByUuid(uuid) {
|
|
483
|
-
return this.
|
|
485
|
+
return this.map.get(uuid);
|
|
484
486
|
}
|
|
485
487
|
push(group) {
|
|
486
488
|
this.subscription(group);
|
|
@@ -523,7 +525,7 @@ class FormArray {
|
|
|
523
525
|
}
|
|
524
526
|
updateValidityStatus(groups, validators) {
|
|
525
527
|
if (validators) {
|
|
526
|
-
const errors =
|
|
528
|
+
const errors = formArrayIsValid({ groups, validators });
|
|
527
529
|
this._errors = errors;
|
|
528
530
|
this._error = errors[0];
|
|
529
531
|
this._valid = errors.length === 0;
|
|
@@ -534,11 +536,11 @@ class FormArray {
|
|
|
534
536
|
this._error = undefined;
|
|
535
537
|
}
|
|
536
538
|
}
|
|
537
|
-
refresh(
|
|
538
|
-
this._groups =
|
|
539
|
-
this.
|
|
539
|
+
refresh(groups) {
|
|
540
|
+
this._groups = groups || [];
|
|
541
|
+
this.map.clear();
|
|
540
542
|
this._groups.forEach((group) => {
|
|
541
|
-
this.
|
|
543
|
+
this.map.set(group.uuid, group);
|
|
542
544
|
});
|
|
543
545
|
this.updateValidityStatus(this._groups, this.validators);
|
|
544
546
|
}
|