@rolster/forms 2.7.2 → 2.8.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.
- package/dist/cjs/arguments.js +46 -46
- package/dist/cjs/arguments.js.map +1 -1
- package/dist/cjs/helpers.js +53 -53
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/index.js +510 -510
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/arguments.js +46 -46
- package/dist/es/arguments.js.map +1 -1
- package/dist/es/helpers.js +53 -53
- package/dist/es/helpers.js.map +1 -1
- package/dist/es/index.js +510 -510
- package/dist/es/index.js.map +1 -1
- package/dist/esm/arguments.d.ts +18 -18
- package/dist/esm/arguments.js +47 -47
- package/dist/esm/arguments.js.map +1 -1
- package/dist/esm/form-array/arguments.d.ts +6 -6
- package/dist/esm/form-array/arguments.js +1 -1
- package/dist/esm/form-array/form-array-control.d.ts +20 -20
- package/dist/esm/form-array/form-array-control.js +13 -13
- package/dist/esm/form-array/form-array-group.d.ts +13 -13
- package/dist/esm/form-array/form-array-group.js +14 -14
- package/dist/esm/form-array/form-array-list.d.ts +20 -20
- package/dist/esm/form-array/form-array-list.js +51 -51
- package/dist/esm/form-array/form-array.d.ts +54 -54
- package/dist/esm/form-array/form-array.js +145 -145
- package/dist/esm/form-array/form-array.js.map +1 -1
- package/dist/esm/form-array/index.d.ts +5 -5
- package/dist/esm/form-array/index.js +5 -5
- package/dist/esm/form-array/types.d.ts +2 -2
- package/dist/esm/form-array/types.js +1 -1
- package/dist/esm/form-control.d.ts +52 -52
- package/dist/esm/form-control.js +119 -119
- package/dist/esm/form-control.js.map +1 -1
- package/dist/esm/form-group.d.ts +34 -34
- package/dist/esm/form-group.js +93 -93
- package/dist/esm/form-group.js.map +1 -1
- package/dist/esm/helpers.d.ts +25 -25
- package/dist/esm/helpers.js +55 -55
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +4 -4
- package/dist/esm/types.d.ts +139 -139
- package/dist/esm/types.js +1 -1
- package/package.json +5 -5
- package/readme.md +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -5,530 +5,530 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var uuid = require('uuid');
|
|
6
6
|
var commons = require('@rolster/commons');
|
|
7
7
|
|
|
8
|
-
function itIsControlOptions(options) {
|
|
9
|
-
return (typeof options === 'object' &&
|
|
10
|
-
('value' in options || 'validators' in options));
|
|
11
|
-
}
|
|
12
|
-
function itIsGroupOptions(options) {
|
|
13
|
-
return typeof options === 'object' && 'controls' in options;
|
|
14
|
-
}
|
|
15
|
-
function itIsArrayOptions(options) {
|
|
16
|
-
return (typeof options === 'object' &&
|
|
17
|
-
('groups' in options || 'validators' in options));
|
|
18
|
-
}
|
|
19
|
-
function createFormControlOptions(...controlOptions) {
|
|
20
|
-
const [options, validators] = controlOptions;
|
|
21
|
-
if (!options) {
|
|
22
|
-
return { value: options, validators };
|
|
23
|
-
}
|
|
24
|
-
if (!validators && itIsControlOptions(options)) {
|
|
25
|
-
return options;
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
value: options,
|
|
29
|
-
validators
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function createFormGroupOptions(...groupOptions) {
|
|
33
|
-
const [options, validators] = groupOptions;
|
|
34
|
-
if (!validators && itIsGroupOptions(options)) {
|
|
35
|
-
return options;
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
controls: options,
|
|
39
|
-
validators
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function createFormArrayOptions(...arrayOptions) {
|
|
43
|
-
const [options, validators] = arrayOptions;
|
|
44
|
-
if (!options) {
|
|
45
|
-
return { groups: options, validators };
|
|
46
|
-
}
|
|
47
|
-
if (!validators && itIsArrayOptions(options)) {
|
|
48
|
-
return options;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
groups: options,
|
|
52
|
-
validators
|
|
53
|
-
};
|
|
8
|
+
function itIsControlOptions(options) {
|
|
9
|
+
return (typeof options === 'object' &&
|
|
10
|
+
('value' in options || 'validators' in options));
|
|
11
|
+
}
|
|
12
|
+
function itIsGroupOptions(options) {
|
|
13
|
+
return typeof options === 'object' && 'controls' in options;
|
|
14
|
+
}
|
|
15
|
+
function itIsArrayOptions(options) {
|
|
16
|
+
return (typeof options === 'object' &&
|
|
17
|
+
('groups' in options || 'validators' in options));
|
|
18
|
+
}
|
|
19
|
+
function createFormControlOptions(...controlOptions) {
|
|
20
|
+
const [options, validators] = controlOptions;
|
|
21
|
+
if (!options) {
|
|
22
|
+
return { value: options, validators };
|
|
23
|
+
}
|
|
24
|
+
if (!validators && itIsControlOptions(options)) {
|
|
25
|
+
return options;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
value: options,
|
|
29
|
+
validators
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function createFormGroupOptions(...groupOptions) {
|
|
33
|
+
const [options, validators] = groupOptions;
|
|
34
|
+
if (!validators && itIsGroupOptions(options)) {
|
|
35
|
+
return options;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
controls: options,
|
|
39
|
+
validators
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function createFormArrayOptions(...arrayOptions) {
|
|
43
|
+
const [options, validators] = arrayOptions;
|
|
44
|
+
if (!options) {
|
|
45
|
+
return { groups: options, validators };
|
|
46
|
+
}
|
|
47
|
+
if (!validators && itIsArrayOptions(options)) {
|
|
48
|
+
return options;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
groups: options,
|
|
52
|
+
validators
|
|
53
|
+
};
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
function reduceErrors(errors) {
|
|
57
|
-
return errors.reduce((keys, { id }) => [...keys, id], []);
|
|
58
|
-
}
|
|
59
|
-
const controlIsValid = ({ value, validators }) => {
|
|
60
|
-
return validators.reduce((errors, validator) => {
|
|
61
|
-
const error = validator(value);
|
|
62
|
-
if (error) {
|
|
63
|
-
errors.push(error);
|
|
64
|
-
}
|
|
65
|
-
return errors;
|
|
66
|
-
}, []);
|
|
67
|
-
};
|
|
68
|
-
const controlsAllChecked = (controls, key) => {
|
|
69
|
-
return Object.values(controls).reduce((value, control) => control.disabled ? value : value && commons.parseBoolean(control[key]), true);
|
|
70
|
-
};
|
|
71
|
-
const controlsPartialChecked = (controls, key) => {
|
|
72
|
-
return Object.values(controls).reduce((value, control) => control.disabled ? value : value || commons.parseBoolean(control[key]), false);
|
|
73
|
-
};
|
|
74
|
-
const controlsToValue = (controls) => {
|
|
75
|
-
return Object.entries(controls).reduce((result, [key, { value }]) => {
|
|
76
|
-
result[key] = value;
|
|
77
|
-
return result;
|
|
78
|
-
}, {});
|
|
79
|
-
};
|
|
80
|
-
const groupIsValid = ({ controls, validators }) => {
|
|
81
|
-
return validators.reduce((errors, validator) => {
|
|
82
|
-
const error = validator(controls);
|
|
83
|
-
if (error) {
|
|
84
|
-
errors.push(error);
|
|
85
|
-
}
|
|
86
|
-
return errors;
|
|
87
|
-
}, []);
|
|
88
|
-
};
|
|
89
|
-
function groupAllChecked(groups, key) {
|
|
90
|
-
return groups.reduce((value, group) => value && commons.parseBoolean(group[key]), true);
|
|
91
|
-
}
|
|
92
|
-
function groupPartialChecked(groups, key) {
|
|
93
|
-
return groups.reduce((value, group) => value || commons.parseBoolean(group[key]), false);
|
|
94
|
-
}
|
|
95
|
-
const arrayIsValid = ({ groups, validators }) => {
|
|
96
|
-
return validators.reduce((errors, validator) => {
|
|
97
|
-
const error = validator(groups);
|
|
98
|
-
if (error) {
|
|
99
|
-
errors.push(error);
|
|
100
|
-
}
|
|
101
|
-
return errors;
|
|
102
|
-
}, []);
|
|
103
|
-
};
|
|
104
|
-
function hasError(errors, key) {
|
|
105
|
-
return reduceErrors(errors).includes(key);
|
|
106
|
-
}
|
|
107
|
-
function someErrors(errors, keys) {
|
|
108
|
-
return reduceErrors(errors).some((key) => keys.includes(key));
|
|
56
|
+
function reduceErrors(errors) {
|
|
57
|
+
return errors.reduce((keys, { id }) => [...keys, id], []);
|
|
58
|
+
}
|
|
59
|
+
const controlIsValid = ({ value, validators }) => {
|
|
60
|
+
return validators.reduce((errors, validator) => {
|
|
61
|
+
const error = validator(value);
|
|
62
|
+
if (error) {
|
|
63
|
+
errors.push(error);
|
|
64
|
+
}
|
|
65
|
+
return errors;
|
|
66
|
+
}, []);
|
|
67
|
+
};
|
|
68
|
+
const controlsAllChecked = (controls, key) => {
|
|
69
|
+
return Object.values(controls).reduce((value, control) => control.disabled ? value : value && commons.parseBoolean(control[key]), true);
|
|
70
|
+
};
|
|
71
|
+
const controlsPartialChecked = (controls, key) => {
|
|
72
|
+
return Object.values(controls).reduce((value, control) => control.disabled ? value : value || commons.parseBoolean(control[key]), false);
|
|
73
|
+
};
|
|
74
|
+
const controlsToValue = (controls) => {
|
|
75
|
+
return Object.entries(controls).reduce((result, [key, { value }]) => {
|
|
76
|
+
result[key] = value;
|
|
77
|
+
return result;
|
|
78
|
+
}, {});
|
|
79
|
+
};
|
|
80
|
+
const groupIsValid = ({ controls, validators }) => {
|
|
81
|
+
return validators.reduce((errors, validator) => {
|
|
82
|
+
const error = validator(controls);
|
|
83
|
+
if (error) {
|
|
84
|
+
errors.push(error);
|
|
85
|
+
}
|
|
86
|
+
return errors;
|
|
87
|
+
}, []);
|
|
88
|
+
};
|
|
89
|
+
function groupAllChecked(groups, key) {
|
|
90
|
+
return groups.reduce((value, group) => value && commons.parseBoolean(group[key]), true);
|
|
91
|
+
}
|
|
92
|
+
function groupPartialChecked(groups, key) {
|
|
93
|
+
return groups.reduce((value, group) => value || commons.parseBoolean(group[key]), false);
|
|
94
|
+
}
|
|
95
|
+
const arrayIsValid = ({ groups, validators }) => {
|
|
96
|
+
return validators.reduce((errors, validator) => {
|
|
97
|
+
const error = validator(groups);
|
|
98
|
+
if (error) {
|
|
99
|
+
errors.push(error);
|
|
100
|
+
}
|
|
101
|
+
return errors;
|
|
102
|
+
}, []);
|
|
103
|
+
};
|
|
104
|
+
function hasError(errors, key) {
|
|
105
|
+
return reduceErrors(errors).includes(key);
|
|
106
|
+
}
|
|
107
|
+
function someErrors(errors, keys) {
|
|
108
|
+
return reduceErrors(errors).some((key) => keys.includes(key));
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
class FormControl {
|
|
112
|
-
constructor(controlOptions, controlValidators) {
|
|
113
|
-
this.currentFocused = false;
|
|
114
|
-
this.currentTouched = false;
|
|
115
|
-
this.currentDirty = false;
|
|
116
|
-
this.currentDisabled = false;
|
|
117
|
-
this.currentValid = true;
|
|
118
|
-
this.currentErrors = [];
|
|
119
|
-
const { value, validators } = createFormControlOptions(controlOptions, controlValidators);
|
|
120
|
-
this.observable = commons.observable(value);
|
|
121
|
-
this.initialValue = value;
|
|
122
|
-
this.validators = validators;
|
|
123
|
-
this.currentValue = value;
|
|
124
|
-
this.updateValueAndValidity(value, validators);
|
|
125
|
-
}
|
|
126
|
-
get focused() {
|
|
127
|
-
return this.currentFocused;
|
|
128
|
-
}
|
|
129
|
-
get unfocused() {
|
|
130
|
-
return !this.currentFocused;
|
|
131
|
-
}
|
|
132
|
-
get touched() {
|
|
133
|
-
return this.currentTouched;
|
|
134
|
-
}
|
|
135
|
-
get untouched() {
|
|
136
|
-
return !this.currentTouched;
|
|
137
|
-
}
|
|
138
|
-
get dirty() {
|
|
139
|
-
return this.currentDirty;
|
|
140
|
-
}
|
|
141
|
-
get pristine() {
|
|
142
|
-
return !this.currentDirty;
|
|
143
|
-
}
|
|
144
|
-
get disabled() {
|
|
145
|
-
return this.currentDisabled;
|
|
146
|
-
}
|
|
147
|
-
get enabled() {
|
|
148
|
-
return !this.currentDisabled;
|
|
149
|
-
}
|
|
150
|
-
get valid() {
|
|
151
|
-
return this.currentValid;
|
|
152
|
-
}
|
|
153
|
-
get invalid() {
|
|
154
|
-
return !this.currentValid;
|
|
155
|
-
}
|
|
156
|
-
get value() {
|
|
157
|
-
return this.currentValue;
|
|
158
|
-
}
|
|
159
|
-
get errors() {
|
|
160
|
-
return this.currentErrors;
|
|
161
|
-
}
|
|
162
|
-
get error() {
|
|
163
|
-
return this.currentError;
|
|
164
|
-
}
|
|
165
|
-
get wrong() {
|
|
166
|
-
return this.touched && this.invalid;
|
|
167
|
-
}
|
|
168
|
-
hasError(key) {
|
|
169
|
-
return hasError(this.errors, key);
|
|
170
|
-
}
|
|
171
|
-
someErrors(keys) {
|
|
172
|
-
return someErrors(this.errors, keys);
|
|
173
|
-
}
|
|
174
|
-
reset() {
|
|
175
|
-
this.setValue(this.initialValue);
|
|
176
|
-
this.currentDirty = false;
|
|
177
|
-
this.currentTouched = false;
|
|
178
|
-
}
|
|
179
|
-
focus() {
|
|
180
|
-
this.currentFocused = true;
|
|
181
|
-
}
|
|
182
|
-
blur() {
|
|
183
|
-
this.currentFocused = false;
|
|
184
|
-
this.currentTouched = true;
|
|
185
|
-
}
|
|
186
|
-
disable() {
|
|
187
|
-
this.currentDisabled = true;
|
|
188
|
-
}
|
|
189
|
-
enable() {
|
|
190
|
-
this.currentDisabled = false;
|
|
191
|
-
}
|
|
192
|
-
touch() {
|
|
193
|
-
this.currentTouched = true;
|
|
194
|
-
}
|
|
195
|
-
setValue(value) {
|
|
196
|
-
if (this.enabled) {
|
|
197
|
-
this.currentValue = value;
|
|
198
|
-
this.currentDirty = true;
|
|
199
|
-
this.updateValueAndValidity(value, this.validators);
|
|
200
|
-
this.observable.next(value);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
setValidators(validators = []) {
|
|
204
|
-
this.validators = validators;
|
|
205
|
-
this.updateValueAndValidity(this.value, validators);
|
|
206
|
-
}
|
|
207
|
-
subscribe(subscriber) {
|
|
208
|
-
return this.observable.subscribe(subscriber);
|
|
209
|
-
}
|
|
210
|
-
updateValueAndValidity(value, validators) {
|
|
211
|
-
if (validators) {
|
|
212
|
-
const errors = controlIsValid({ value, validators });
|
|
213
|
-
this.currentError = errors[0];
|
|
214
|
-
this.currentErrors = errors;
|
|
215
|
-
this.currentValid = errors.length === 0;
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
this.currentValid = true;
|
|
219
|
-
this.currentError = undefined;
|
|
220
|
-
this.currentErrors = [];
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
function formControl(options, validators) {
|
|
225
|
-
return new FormControl(createFormControlOptions(options, validators));
|
|
111
|
+
class FormControl {
|
|
112
|
+
constructor(controlOptions, controlValidators) {
|
|
113
|
+
this.currentFocused = false;
|
|
114
|
+
this.currentTouched = false;
|
|
115
|
+
this.currentDirty = false;
|
|
116
|
+
this.currentDisabled = false;
|
|
117
|
+
this.currentValid = true;
|
|
118
|
+
this.currentErrors = [];
|
|
119
|
+
const { value, validators } = createFormControlOptions(controlOptions, controlValidators);
|
|
120
|
+
this.observable = commons.observable(value);
|
|
121
|
+
this.initialValue = value;
|
|
122
|
+
this.validators = validators;
|
|
123
|
+
this.currentValue = value;
|
|
124
|
+
this.updateValueAndValidity(value, validators);
|
|
125
|
+
}
|
|
126
|
+
get focused() {
|
|
127
|
+
return this.currentFocused;
|
|
128
|
+
}
|
|
129
|
+
get unfocused() {
|
|
130
|
+
return !this.currentFocused;
|
|
131
|
+
}
|
|
132
|
+
get touched() {
|
|
133
|
+
return this.currentTouched;
|
|
134
|
+
}
|
|
135
|
+
get untouched() {
|
|
136
|
+
return !this.currentTouched;
|
|
137
|
+
}
|
|
138
|
+
get dirty() {
|
|
139
|
+
return this.currentDirty;
|
|
140
|
+
}
|
|
141
|
+
get pristine() {
|
|
142
|
+
return !this.currentDirty;
|
|
143
|
+
}
|
|
144
|
+
get disabled() {
|
|
145
|
+
return this.currentDisabled;
|
|
146
|
+
}
|
|
147
|
+
get enabled() {
|
|
148
|
+
return !this.currentDisabled;
|
|
149
|
+
}
|
|
150
|
+
get valid() {
|
|
151
|
+
return this.currentValid;
|
|
152
|
+
}
|
|
153
|
+
get invalid() {
|
|
154
|
+
return !this.currentValid;
|
|
155
|
+
}
|
|
156
|
+
get value() {
|
|
157
|
+
return this.currentValue;
|
|
158
|
+
}
|
|
159
|
+
get errors() {
|
|
160
|
+
return this.currentErrors;
|
|
161
|
+
}
|
|
162
|
+
get error() {
|
|
163
|
+
return this.currentError;
|
|
164
|
+
}
|
|
165
|
+
get wrong() {
|
|
166
|
+
return this.touched && this.invalid;
|
|
167
|
+
}
|
|
168
|
+
hasError(key) {
|
|
169
|
+
return hasError(this.errors, key);
|
|
170
|
+
}
|
|
171
|
+
someErrors(keys) {
|
|
172
|
+
return someErrors(this.errors, keys);
|
|
173
|
+
}
|
|
174
|
+
reset() {
|
|
175
|
+
this.setValue(this.initialValue);
|
|
176
|
+
this.currentDirty = false;
|
|
177
|
+
this.currentTouched = false;
|
|
178
|
+
}
|
|
179
|
+
focus() {
|
|
180
|
+
this.currentFocused = true;
|
|
181
|
+
}
|
|
182
|
+
blur() {
|
|
183
|
+
this.currentFocused = false;
|
|
184
|
+
this.currentTouched = true;
|
|
185
|
+
}
|
|
186
|
+
disable() {
|
|
187
|
+
this.currentDisabled = true;
|
|
188
|
+
}
|
|
189
|
+
enable() {
|
|
190
|
+
this.currentDisabled = false;
|
|
191
|
+
}
|
|
192
|
+
touch() {
|
|
193
|
+
this.currentTouched = true;
|
|
194
|
+
}
|
|
195
|
+
setValue(value) {
|
|
196
|
+
if (this.enabled) {
|
|
197
|
+
this.currentValue = value;
|
|
198
|
+
this.currentDirty = true;
|
|
199
|
+
this.updateValueAndValidity(value, this.validators);
|
|
200
|
+
this.observable.next(value);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
setValidators(validators = []) {
|
|
204
|
+
this.validators = validators;
|
|
205
|
+
this.updateValueAndValidity(this.value, validators);
|
|
206
|
+
}
|
|
207
|
+
subscribe(subscriber) {
|
|
208
|
+
return this.observable.subscribe(subscriber);
|
|
209
|
+
}
|
|
210
|
+
updateValueAndValidity(value, validators) {
|
|
211
|
+
if (validators) {
|
|
212
|
+
const errors = controlIsValid({ value, validators });
|
|
213
|
+
this.currentError = errors[0];
|
|
214
|
+
this.currentErrors = errors;
|
|
215
|
+
this.currentValid = errors.length === 0;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
this.currentValid = true;
|
|
219
|
+
this.currentError = undefined;
|
|
220
|
+
this.currentErrors = [];
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function formControl(options, validators) {
|
|
225
|
+
return new FormControl(createFormControlOptions(options, validators));
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
class FormArrayControl extends FormControl {
|
|
229
|
-
constructor(controlOptions, controlValidators) {
|
|
230
|
-
const { value, validators } = createFormControlOptions(controlOptions, controlValidators);
|
|
231
|
-
super(value, validators);
|
|
232
|
-
this.uuid = uuid.v4();
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
function formArrayControl(options, validators) {
|
|
236
|
-
return new FormArrayControl(createFormControlOptions(options, validators));
|
|
228
|
+
class FormArrayControl extends FormControl {
|
|
229
|
+
constructor(controlOptions, controlValidators) {
|
|
230
|
+
const { value, validators } = createFormControlOptions(controlOptions, controlValidators);
|
|
231
|
+
super(value, validators);
|
|
232
|
+
this.uuid = uuid.v4();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function formArrayControl(options, validators) {
|
|
236
|
+
return new FormArrayControl(createFormControlOptions(options, validators));
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
class FormGroup {
|
|
240
|
-
constructor(groupOptions, groupValidators) {
|
|
241
|
-
this.currentErrors = [];
|
|
242
|
-
this.currentValid = true;
|
|
243
|
-
const { controls, validators } = createFormGroupOptions(groupOptions, groupValidators);
|
|
244
|
-
this.currentControls = controls;
|
|
245
|
-
this.validators = validators;
|
|
246
|
-
this.updateValueAndValidity(controls, validators);
|
|
247
|
-
this.observable = commons.observable(this.value);
|
|
248
|
-
Object.values(controls).forEach((control) => {
|
|
249
|
-
control.subscribe(() => {
|
|
250
|
-
this.updateValueAndValidity(this.controls, this.validators);
|
|
251
|
-
this.observable.next(this.value);
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
get controls() {
|
|
256
|
-
return this.currentControls;
|
|
257
|
-
}
|
|
258
|
-
get touched() {
|
|
259
|
-
return controlsPartialChecked(this.controls, 'touched');
|
|
260
|
-
}
|
|
261
|
-
get touchedAll() {
|
|
262
|
-
return controlsAllChecked(this.controls, 'touched');
|
|
263
|
-
}
|
|
264
|
-
get untouched() {
|
|
265
|
-
return !this.touched;
|
|
266
|
-
}
|
|
267
|
-
get untouchedAll() {
|
|
268
|
-
return !this.touchedAll;
|
|
269
|
-
}
|
|
270
|
-
get dirty() {
|
|
271
|
-
return controlsPartialChecked(this.controls, 'dirty');
|
|
272
|
-
}
|
|
273
|
-
get dirtyAll() {
|
|
274
|
-
return controlsAllChecked(this.controls, 'dirty');
|
|
275
|
-
}
|
|
276
|
-
get pristine() {
|
|
277
|
-
return !this.dirty;
|
|
278
|
-
}
|
|
279
|
-
get pristineAll() {
|
|
280
|
-
return this.dirtyAll;
|
|
281
|
-
}
|
|
282
|
-
get valid() {
|
|
283
|
-
return this.currentValid && controlsAllChecked(this.controls, 'valid');
|
|
284
|
-
}
|
|
285
|
-
get invalid() {
|
|
286
|
-
return !this.valid;
|
|
287
|
-
}
|
|
288
|
-
get value() {
|
|
289
|
-
return controlsToValue(this.controls);
|
|
290
|
-
}
|
|
291
|
-
get errors() {
|
|
292
|
-
return this.currentErrors;
|
|
293
|
-
}
|
|
294
|
-
get error() {
|
|
295
|
-
return this.currentError;
|
|
296
|
-
}
|
|
297
|
-
get wrong() {
|
|
298
|
-
return this.touched && this.invalid;
|
|
299
|
-
}
|
|
300
|
-
reset() {
|
|
301
|
-
Object.values(this.controls).forEach((control) => {
|
|
302
|
-
control.reset();
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
setValidators(validators) {
|
|
306
|
-
this.validators = validators;
|
|
307
|
-
this.updateValueAndValidity(this.controls, validators);
|
|
308
|
-
}
|
|
309
|
-
subscribe(subscriber) {
|
|
310
|
-
return this.observable.subscribe(subscriber);
|
|
311
|
-
}
|
|
312
|
-
updateValueAndValidity(controls, validators) {
|
|
313
|
-
if (validators) {
|
|
314
|
-
const errors = groupIsValid({ controls, validators });
|
|
315
|
-
this.currentErrors = errors;
|
|
316
|
-
this.currentError = errors[0];
|
|
317
|
-
this.currentValid = errors.length === 0;
|
|
318
|
-
}
|
|
319
|
-
else {
|
|
320
|
-
this.currentErrors = [];
|
|
321
|
-
this.currentError = undefined;
|
|
322
|
-
this.currentValid = true;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
function formGroup(options, validators) {
|
|
327
|
-
return new FormGroup(createFormGroupOptions(options, validators));
|
|
239
|
+
class FormGroup {
|
|
240
|
+
constructor(groupOptions, groupValidators) {
|
|
241
|
+
this.currentErrors = [];
|
|
242
|
+
this.currentValid = true;
|
|
243
|
+
const { controls, validators } = createFormGroupOptions(groupOptions, groupValidators);
|
|
244
|
+
this.currentControls = controls;
|
|
245
|
+
this.validators = validators;
|
|
246
|
+
this.updateValueAndValidity(controls, validators);
|
|
247
|
+
this.observable = commons.observable(this.value);
|
|
248
|
+
Object.values(controls).forEach((control) => {
|
|
249
|
+
control.subscribe(() => {
|
|
250
|
+
this.updateValueAndValidity(this.controls, this.validators);
|
|
251
|
+
this.observable.next(this.value);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
get controls() {
|
|
256
|
+
return this.currentControls;
|
|
257
|
+
}
|
|
258
|
+
get touched() {
|
|
259
|
+
return controlsPartialChecked(this.controls, 'touched');
|
|
260
|
+
}
|
|
261
|
+
get touchedAll() {
|
|
262
|
+
return controlsAllChecked(this.controls, 'touched');
|
|
263
|
+
}
|
|
264
|
+
get untouched() {
|
|
265
|
+
return !this.touched;
|
|
266
|
+
}
|
|
267
|
+
get untouchedAll() {
|
|
268
|
+
return !this.touchedAll;
|
|
269
|
+
}
|
|
270
|
+
get dirty() {
|
|
271
|
+
return controlsPartialChecked(this.controls, 'dirty');
|
|
272
|
+
}
|
|
273
|
+
get dirtyAll() {
|
|
274
|
+
return controlsAllChecked(this.controls, 'dirty');
|
|
275
|
+
}
|
|
276
|
+
get pristine() {
|
|
277
|
+
return !this.dirty;
|
|
278
|
+
}
|
|
279
|
+
get pristineAll() {
|
|
280
|
+
return this.dirtyAll;
|
|
281
|
+
}
|
|
282
|
+
get valid() {
|
|
283
|
+
return this.currentValid && controlsAllChecked(this.controls, 'valid');
|
|
284
|
+
}
|
|
285
|
+
get invalid() {
|
|
286
|
+
return !this.valid;
|
|
287
|
+
}
|
|
288
|
+
get value() {
|
|
289
|
+
return controlsToValue(this.controls);
|
|
290
|
+
}
|
|
291
|
+
get errors() {
|
|
292
|
+
return this.currentErrors;
|
|
293
|
+
}
|
|
294
|
+
get error() {
|
|
295
|
+
return this.currentError;
|
|
296
|
+
}
|
|
297
|
+
get wrong() {
|
|
298
|
+
return this.touched && this.invalid;
|
|
299
|
+
}
|
|
300
|
+
reset() {
|
|
301
|
+
Object.values(this.controls).forEach((control) => {
|
|
302
|
+
control.reset();
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
setValidators(validators) {
|
|
306
|
+
this.validators = validators;
|
|
307
|
+
this.updateValueAndValidity(this.controls, validators);
|
|
308
|
+
}
|
|
309
|
+
subscribe(subscriber) {
|
|
310
|
+
return this.observable.subscribe(subscriber);
|
|
311
|
+
}
|
|
312
|
+
updateValueAndValidity(controls, validators) {
|
|
313
|
+
if (validators) {
|
|
314
|
+
const errors = groupIsValid({ controls, validators });
|
|
315
|
+
this.currentErrors = errors;
|
|
316
|
+
this.currentError = errors[0];
|
|
317
|
+
this.currentValid = errors.length === 0;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
this.currentErrors = [];
|
|
321
|
+
this.currentError = undefined;
|
|
322
|
+
this.currentValid = true;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function formGroup(options, validators) {
|
|
327
|
+
return new FormGroup(createFormGroupOptions(options, validators));
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
-
class FormArrayGroup extends FormGroup {
|
|
331
|
-
constructor(groupOptions, groupValidators) {
|
|
332
|
-
const { controls, resource, validators } = createFormGroupOptions(groupOptions, groupValidators);
|
|
333
|
-
super(controls, validators);
|
|
334
|
-
this.uuid = uuid.v4();
|
|
335
|
-
this.resource = resource;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
function formArrayGroup(options, validators) {
|
|
339
|
-
return new FormArrayGroup(createFormGroupOptions(options, validators));
|
|
330
|
+
class FormArrayGroup extends FormGroup {
|
|
331
|
+
constructor(groupOptions, groupValidators) {
|
|
332
|
+
const { controls, resource, validators } = createFormGroupOptions(groupOptions, groupValidators);
|
|
333
|
+
super(controls, validators);
|
|
334
|
+
this.uuid = uuid.v4();
|
|
335
|
+
this.resource = resource;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function formArrayGroup(options, validators) {
|
|
339
|
+
return new FormArrayGroup(createFormGroupOptions(options, validators));
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
-
class FormArrayList extends FormControl {
|
|
343
|
-
constructor(valueToControls, value, validators) {
|
|
344
|
-
const initialValue = value || [];
|
|
345
|
-
super(initialValue, validators);
|
|
346
|
-
this.valueToControls = valueToControls;
|
|
347
|
-
this.currentControls = initialValue.map((value) => this.createControls(value));
|
|
348
|
-
this.uuid = uuid.v4();
|
|
349
|
-
}
|
|
350
|
-
get controls() {
|
|
351
|
-
return this.currentControls;
|
|
352
|
-
}
|
|
353
|
-
get touched() {
|
|
354
|
-
return this.controls.reduce((valid, controls) => valid && controlsPartialChecked(controls, 'touched'), true);
|
|
355
|
-
}
|
|
356
|
-
get dirty() {
|
|
357
|
-
return this.controls.reduce((valid, controls) => valid && controlsPartialChecked(controls, 'dirty'), true);
|
|
358
|
-
}
|
|
359
|
-
get valid() {
|
|
360
|
-
return (this.currentValid &&
|
|
361
|
-
this.controls.reduce((valid, controls) => valid && controlsAllChecked(controls, 'valid'), true));
|
|
362
|
-
}
|
|
363
|
-
get value() {
|
|
364
|
-
return this.controls.map((controls) => controlsToValue(controls));
|
|
365
|
-
}
|
|
366
|
-
setValue(values) {
|
|
367
|
-
this.currentControls = values.map((value) => this.createControls(value));
|
|
368
|
-
}
|
|
369
|
-
push(controls) {
|
|
370
|
-
this.currentControls = this.currentControls.concat([controls]);
|
|
371
|
-
}
|
|
372
|
-
remove(controls) {
|
|
373
|
-
this.currentControls = this.currentControls.filter((currentControls) => currentControls !== controls);
|
|
374
|
-
}
|
|
375
|
-
createControls(value) {
|
|
376
|
-
const controls = this.valueToControls(value);
|
|
377
|
-
Object.values(controls).forEach((control) => {
|
|
378
|
-
control.subscribe(() => {
|
|
379
|
-
const { value, validators } = this;
|
|
380
|
-
this.updateValueAndValidity(value, validators);
|
|
381
|
-
this.observable.next(value);
|
|
382
|
-
});
|
|
383
|
-
});
|
|
384
|
-
return controls;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
function formArrayList(valueToControl, value, validators) {
|
|
388
|
-
return new FormArrayList(valueToControl, value, validators);
|
|
342
|
+
class FormArrayList extends FormControl {
|
|
343
|
+
constructor(valueToControls, value, validators) {
|
|
344
|
+
const initialValue = value || [];
|
|
345
|
+
super(initialValue, validators);
|
|
346
|
+
this.valueToControls = valueToControls;
|
|
347
|
+
this.currentControls = initialValue.map((value) => this.createControls(value));
|
|
348
|
+
this.uuid = uuid.v4();
|
|
349
|
+
}
|
|
350
|
+
get controls() {
|
|
351
|
+
return this.currentControls;
|
|
352
|
+
}
|
|
353
|
+
get touched() {
|
|
354
|
+
return this.controls.reduce((valid, controls) => valid && controlsPartialChecked(controls, 'touched'), true);
|
|
355
|
+
}
|
|
356
|
+
get dirty() {
|
|
357
|
+
return this.controls.reduce((valid, controls) => valid && controlsPartialChecked(controls, 'dirty'), true);
|
|
358
|
+
}
|
|
359
|
+
get valid() {
|
|
360
|
+
return (this.currentValid &&
|
|
361
|
+
this.controls.reduce((valid, controls) => valid && controlsAllChecked(controls, 'valid'), true));
|
|
362
|
+
}
|
|
363
|
+
get value() {
|
|
364
|
+
return this.controls.map((controls) => controlsToValue(controls));
|
|
365
|
+
}
|
|
366
|
+
setValue(values) {
|
|
367
|
+
this.currentControls = values.map((value) => this.createControls(value));
|
|
368
|
+
}
|
|
369
|
+
push(controls) {
|
|
370
|
+
this.currentControls = this.currentControls.concat([controls]);
|
|
371
|
+
}
|
|
372
|
+
remove(controls) {
|
|
373
|
+
this.currentControls = this.currentControls.filter((currentControls) => currentControls !== controls);
|
|
374
|
+
}
|
|
375
|
+
createControls(value) {
|
|
376
|
+
const controls = this.valueToControls(value);
|
|
377
|
+
Object.values(controls).forEach((control) => {
|
|
378
|
+
control.subscribe(() => {
|
|
379
|
+
const { value, validators } = this;
|
|
380
|
+
this.updateValueAndValidity(value, validators);
|
|
381
|
+
this.observable.next(value);
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
return controls;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function formArrayList(valueToControl, value, validators) {
|
|
388
|
+
return new FormArrayList(valueToControl, value, validators);
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
class FormArray {
|
|
392
|
-
constructor(arrayOptions, arrayValidators) {
|
|
393
|
-
this.currentGroups = [];
|
|
394
|
-
this.currentValid = true;
|
|
395
|
-
this.currentDisabled = false;
|
|
396
|
-
this.currentErrors = [];
|
|
397
|
-
const { groups, validators } = createFormArrayOptions(arrayOptions, arrayValidators);
|
|
398
|
-
this.unsusbcriptions = new Map();
|
|
399
|
-
this.initialState = groups;
|
|
400
|
-
this.validators = validators;
|
|
401
|
-
this.refresh(this.initialState);
|
|
402
|
-
this.observable = commons.observable(this.value);
|
|
403
|
-
groups?.forEach((group) => {
|
|
404
|
-
this.subscription(group);
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
get groups() {
|
|
408
|
-
return this.currentGroups;
|
|
409
|
-
}
|
|
410
|
-
get controls() {
|
|
411
|
-
return this.groups.map(({ controls }) => controls);
|
|
412
|
-
}
|
|
413
|
-
get touched() {
|
|
414
|
-
return groupPartialChecked(this.groups, 'touched');
|
|
415
|
-
}
|
|
416
|
-
get touchedAll() {
|
|
417
|
-
return groupAllChecked(this.groups, 'touchedAll');
|
|
418
|
-
}
|
|
419
|
-
get untouched() {
|
|
420
|
-
return !this.touched;
|
|
421
|
-
}
|
|
422
|
-
get untouchedAll() {
|
|
423
|
-
return !this.touchedAll;
|
|
424
|
-
}
|
|
425
|
-
get dirty() {
|
|
426
|
-
return groupPartialChecked(this.groups, 'dirty');
|
|
427
|
-
}
|
|
428
|
-
get dirtyAll() {
|
|
429
|
-
return groupAllChecked(this.groups, 'dirtyAll');
|
|
430
|
-
}
|
|
431
|
-
get pristine() {
|
|
432
|
-
return !this.dirty;
|
|
433
|
-
}
|
|
434
|
-
get pristineAll() {
|
|
435
|
-
return !this.dirtyAll;
|
|
436
|
-
}
|
|
437
|
-
get disabled() {
|
|
438
|
-
return this.currentDisabled;
|
|
439
|
-
}
|
|
440
|
-
get enabled() {
|
|
441
|
-
return !this.currentDisabled;
|
|
442
|
-
}
|
|
443
|
-
get valid() {
|
|
444
|
-
return this.currentValid && groupAllChecked(this.groups, 'valid');
|
|
445
|
-
}
|
|
446
|
-
get invalid() {
|
|
447
|
-
return !this.currentValid;
|
|
448
|
-
}
|
|
449
|
-
get value() {
|
|
450
|
-
return this.groups.map(({ value: state }) => state);
|
|
451
|
-
}
|
|
452
|
-
get error() {
|
|
453
|
-
return this.currentError;
|
|
454
|
-
}
|
|
455
|
-
get errors() {
|
|
456
|
-
return this.currentErrors;
|
|
457
|
-
}
|
|
458
|
-
get wrong() {
|
|
459
|
-
return this.touched && this.invalid;
|
|
460
|
-
}
|
|
461
|
-
hasError(key) {
|
|
462
|
-
return hasError(this.errors, key);
|
|
463
|
-
}
|
|
464
|
-
someErrors(keys) {
|
|
465
|
-
return someErrors(this.errors, keys);
|
|
466
|
-
}
|
|
467
|
-
reset() {
|
|
468
|
-
this.refresh(this.initialState);
|
|
469
|
-
}
|
|
470
|
-
disable() {
|
|
471
|
-
this.currentDisabled = true;
|
|
472
|
-
}
|
|
473
|
-
enable() {
|
|
474
|
-
this.currentDisabled = false;
|
|
475
|
-
}
|
|
476
|
-
push(group) {
|
|
477
|
-
this.subscription(group);
|
|
478
|
-
this.refresh([...this.groups, group]);
|
|
479
|
-
}
|
|
480
|
-
merge(groups) {
|
|
481
|
-
groups.forEach((group) => {
|
|
482
|
-
this.subscription(group);
|
|
483
|
-
});
|
|
484
|
-
this.refresh([...this.groups, ...groups]);
|
|
485
|
-
}
|
|
486
|
-
set(groups) {
|
|
487
|
-
this.currentGroups.forEach(({ uuid }) => {
|
|
488
|
-
this.unsusbcriptions.delete(uuid);
|
|
489
|
-
});
|
|
490
|
-
groups.forEach((group) => {
|
|
491
|
-
this.subscription(group);
|
|
492
|
-
});
|
|
493
|
-
this.refresh(groups); // Update groups
|
|
494
|
-
}
|
|
495
|
-
remove({ uuid }) {
|
|
496
|
-
this.refresh(this.groups.filter((group) => group.uuid !== uuid));
|
|
497
|
-
}
|
|
498
|
-
setValidators(validators) {
|
|
499
|
-
this.validators = validators;
|
|
500
|
-
this.updateValidityStatus(this.groups, validators);
|
|
501
|
-
}
|
|
502
|
-
subscribe(subscriber) {
|
|
503
|
-
return this.observable.subscribe(subscriber);
|
|
504
|
-
}
|
|
505
|
-
subscription(group) {
|
|
506
|
-
const unsusbcription = group.subscribe(() => {
|
|
507
|
-
this.updateValidityStatus(this.groups, this.validators);
|
|
508
|
-
});
|
|
509
|
-
this.unsusbcriptions.set(group.uuid, unsusbcription);
|
|
510
|
-
}
|
|
511
|
-
updateValidityStatus(groups, validators) {
|
|
512
|
-
if (validators) {
|
|
513
|
-
const errors = arrayIsValid({ groups, validators });
|
|
514
|
-
this.currentErrors = errors;
|
|
515
|
-
this.currentError = errors[0];
|
|
516
|
-
this.currentValid = errors.length === 0;
|
|
517
|
-
}
|
|
518
|
-
else {
|
|
519
|
-
this.currentValid = true;
|
|
520
|
-
this.currentErrors = [];
|
|
521
|
-
this.currentError = undefined;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
refresh(newGroups) {
|
|
525
|
-
const groups = newGroups || [];
|
|
526
|
-
this.currentGroups = groups;
|
|
527
|
-
this.updateValidityStatus(groups, this.validators);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
function formArray(options, validators) {
|
|
531
|
-
return new FormArray(createFormArrayOptions(options, validators));
|
|
391
|
+
class FormArray {
|
|
392
|
+
constructor(arrayOptions, arrayValidators) {
|
|
393
|
+
this.currentGroups = [];
|
|
394
|
+
this.currentValid = true;
|
|
395
|
+
this.currentDisabled = false;
|
|
396
|
+
this.currentErrors = [];
|
|
397
|
+
const { groups, validators } = createFormArrayOptions(arrayOptions, arrayValidators);
|
|
398
|
+
this.unsusbcriptions = new Map();
|
|
399
|
+
this.initialState = groups;
|
|
400
|
+
this.validators = validators;
|
|
401
|
+
this.refresh(this.initialState);
|
|
402
|
+
this.observable = commons.observable(this.value);
|
|
403
|
+
groups?.forEach((group) => {
|
|
404
|
+
this.subscription(group);
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
get groups() {
|
|
408
|
+
return this.currentGroups;
|
|
409
|
+
}
|
|
410
|
+
get controls() {
|
|
411
|
+
return this.groups.map(({ controls }) => controls);
|
|
412
|
+
}
|
|
413
|
+
get touched() {
|
|
414
|
+
return groupPartialChecked(this.groups, 'touched');
|
|
415
|
+
}
|
|
416
|
+
get touchedAll() {
|
|
417
|
+
return groupAllChecked(this.groups, 'touchedAll');
|
|
418
|
+
}
|
|
419
|
+
get untouched() {
|
|
420
|
+
return !this.touched;
|
|
421
|
+
}
|
|
422
|
+
get untouchedAll() {
|
|
423
|
+
return !this.touchedAll;
|
|
424
|
+
}
|
|
425
|
+
get dirty() {
|
|
426
|
+
return groupPartialChecked(this.groups, 'dirty');
|
|
427
|
+
}
|
|
428
|
+
get dirtyAll() {
|
|
429
|
+
return groupAllChecked(this.groups, 'dirtyAll');
|
|
430
|
+
}
|
|
431
|
+
get pristine() {
|
|
432
|
+
return !this.dirty;
|
|
433
|
+
}
|
|
434
|
+
get pristineAll() {
|
|
435
|
+
return !this.dirtyAll;
|
|
436
|
+
}
|
|
437
|
+
get disabled() {
|
|
438
|
+
return this.currentDisabled;
|
|
439
|
+
}
|
|
440
|
+
get enabled() {
|
|
441
|
+
return !this.currentDisabled;
|
|
442
|
+
}
|
|
443
|
+
get valid() {
|
|
444
|
+
return this.currentValid && groupAllChecked(this.groups, 'valid');
|
|
445
|
+
}
|
|
446
|
+
get invalid() {
|
|
447
|
+
return !this.currentValid;
|
|
448
|
+
}
|
|
449
|
+
get value() {
|
|
450
|
+
return this.groups.map(({ value: state }) => state);
|
|
451
|
+
}
|
|
452
|
+
get error() {
|
|
453
|
+
return this.currentError;
|
|
454
|
+
}
|
|
455
|
+
get errors() {
|
|
456
|
+
return this.currentErrors;
|
|
457
|
+
}
|
|
458
|
+
get wrong() {
|
|
459
|
+
return this.touched && this.invalid;
|
|
460
|
+
}
|
|
461
|
+
hasError(key) {
|
|
462
|
+
return hasError(this.errors, key);
|
|
463
|
+
}
|
|
464
|
+
someErrors(keys) {
|
|
465
|
+
return someErrors(this.errors, keys);
|
|
466
|
+
}
|
|
467
|
+
reset() {
|
|
468
|
+
this.refresh(this.initialState);
|
|
469
|
+
}
|
|
470
|
+
disable() {
|
|
471
|
+
this.currentDisabled = true;
|
|
472
|
+
}
|
|
473
|
+
enable() {
|
|
474
|
+
this.currentDisabled = false;
|
|
475
|
+
}
|
|
476
|
+
push(group) {
|
|
477
|
+
this.subscription(group);
|
|
478
|
+
this.refresh([...this.groups, group]);
|
|
479
|
+
}
|
|
480
|
+
merge(groups) {
|
|
481
|
+
groups.forEach((group) => {
|
|
482
|
+
this.subscription(group);
|
|
483
|
+
});
|
|
484
|
+
this.refresh([...this.groups, ...groups]);
|
|
485
|
+
}
|
|
486
|
+
set(groups) {
|
|
487
|
+
this.currentGroups.forEach(({ uuid }) => {
|
|
488
|
+
this.unsusbcriptions.delete(uuid);
|
|
489
|
+
});
|
|
490
|
+
groups.forEach((group) => {
|
|
491
|
+
this.subscription(group);
|
|
492
|
+
});
|
|
493
|
+
this.refresh(groups); // Update groups
|
|
494
|
+
}
|
|
495
|
+
remove({ uuid }) {
|
|
496
|
+
this.refresh(this.groups.filter((group) => group.uuid !== uuid));
|
|
497
|
+
}
|
|
498
|
+
setValidators(validators) {
|
|
499
|
+
this.validators = validators;
|
|
500
|
+
this.updateValidityStatus(this.groups, validators);
|
|
501
|
+
}
|
|
502
|
+
subscribe(subscriber) {
|
|
503
|
+
return this.observable.subscribe(subscriber);
|
|
504
|
+
}
|
|
505
|
+
subscription(group) {
|
|
506
|
+
const unsusbcription = group.subscribe(() => {
|
|
507
|
+
this.updateValidityStatus(this.groups, this.validators);
|
|
508
|
+
});
|
|
509
|
+
this.unsusbcriptions.set(group.uuid, unsusbcription);
|
|
510
|
+
}
|
|
511
|
+
updateValidityStatus(groups, validators) {
|
|
512
|
+
if (validators) {
|
|
513
|
+
const errors = arrayIsValid({ groups, validators });
|
|
514
|
+
this.currentErrors = errors;
|
|
515
|
+
this.currentError = errors[0];
|
|
516
|
+
this.currentValid = errors.length === 0;
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
this.currentValid = true;
|
|
520
|
+
this.currentErrors = [];
|
|
521
|
+
this.currentError = undefined;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
refresh(newGroups) {
|
|
525
|
+
const groups = newGroups || [];
|
|
526
|
+
this.currentGroups = groups;
|
|
527
|
+
this.updateValidityStatus(groups, this.validators);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function formArray(options, validators) {
|
|
531
|
+
return new FormArray(createFormArrayOptions(options, validators));
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
exports.FormArray = FormArray;
|