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