@rolster/forms 2.8.0 → 2.10.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/helpers.js +8 -0
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/index.js +127 -119
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/helpers.js +7 -1
- package/dist/es/helpers.js.map +1 -1
- package/dist/es/index.js +127 -119
- package/dist/es/index.js.map +1 -1
- package/dist/esm/form-array/form-array-control.js +3 -3
- package/dist/esm/form-array/form-array-control.js.map +1 -1
- package/dist/esm/form-array/form-array-group.js +4 -4
- package/dist/esm/form-array/form-array-group.js.map +1 -1
- package/dist/esm/form-array/form-array-list.d.ts +1 -1
- 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.d.ts +12 -11
- package/dist/esm/form-array/form-array.js +41 -37
- package/dist/esm/form-array/form-array.js.map +1 -1
- package/dist/esm/form-control.d.ts +10 -9
- package/dist/esm/form-control.js +47 -43
- package/dist/esm/form-control.js.map +1 -1
- package/dist/esm/form-group.d.ts +8 -8
- package/dist/esm/form-group.js +24 -24
- package/dist/esm/form-group.js.map +1 -1
- package/dist/esm/helpers.d.ts +3 -1
- package/dist/esm/helpers.js +6 -0
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/types.d.ts +11 -9
- package/package.json +2 -2
package/dist/cjs/helpers.js
CHANGED
|
@@ -58,6 +58,12 @@ function hasError(errors, key) {
|
|
|
58
58
|
function someErrors(errors, keys) {
|
|
59
59
|
return reduceErrors(errors).some((key) => keys.includes(key));
|
|
60
60
|
}
|
|
61
|
+
function reduceControlsToArray(controls, key) {
|
|
62
|
+
return Object.values(controls).map((control) => control[key]);
|
|
63
|
+
}
|
|
64
|
+
function reduceGroupToArray(group, key) {
|
|
65
|
+
return reduceControlsToArray(group.controls, key);
|
|
66
|
+
}
|
|
61
67
|
|
|
62
68
|
exports.arrayIsValid = arrayIsValid;
|
|
63
69
|
exports.controlIsValid = controlIsValid;
|
|
@@ -68,5 +74,7 @@ exports.groupAllChecked = groupAllChecked;
|
|
|
68
74
|
exports.groupIsValid = groupIsValid;
|
|
69
75
|
exports.groupPartialChecked = groupPartialChecked;
|
|
70
76
|
exports.hasError = hasError;
|
|
77
|
+
exports.reduceControlsToArray = reduceControlsToArray;
|
|
78
|
+
exports.reduceGroupToArray = reduceGroupToArray;
|
|
71
79
|
exports.someErrors = someErrors;
|
|
72
80
|
//# 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 reduceErrors(errors) {\n return errors.reduce((keys, { id }) => [...keys, id], []);\n}\nexport const controlIsValid = ({ 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};\nexport const controlsAllChecked = (controls, key) => {\n return Object.values(controls).reduce((value, control) => control.disabled ? value : value && parseBoolean(control[key]), true);\n};\nexport const controlsPartialChecked = (controls, key) => {\n return Object.values(controls).reduce((value, control) => control.disabled ? value : value || parseBoolean(control[key]), false);\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 groupIsValid = ({ 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 function groupAllChecked(groups, key) {\n return groups.reduce((value, group) => value && parseBoolean(group[key]), true);\n}\nexport function groupPartialChecked(groups, key) {\n return groups.reduce((value, group) => value || parseBoolean(group[key]), false);\n}\nexport const arrayIsValid = ({ 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 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}\n//# sourceMappingURL=helpers.js.map"],"names":["parseBoolean"],"mappings":";;;;;;AACA,SAAS,YAAY,CAAC,MAAM,EAAE;AAC9B,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9D,CAAC;AACW,MAAC,cAAc,GAAG,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK;AACzD,IAAI,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,SAAS,KAAK;AACpD,QAAQ,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;AACvC,QAAQ,IAAI,KAAK,EAAE;AACnB,YAAY,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/B,SAAS;AACT,QAAQ,OAAO,MAAM,CAAC;AACtB,KAAK,EAAE,EAAE,CAAC,CAAC;AACX,EAAE;AACU,MAAC,kBAAkB,GAAG,CAAC,QAAQ,EAAE,GAAG,KAAK;AACrD,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,KAAK,GAAG,KAAK,IAAIA,oBAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AACpI,EAAE;AACU,MAAC,sBAAsB,GAAG,CAAC,QAAQ,EAAE,GAAG,KAAK;AACzD,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,KAAK,GAAG,KAAK,IAAIA,oB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AE,MAAM,EAAE,UAAU,EAAE,KAAK;AACxD,IAAI,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,SAAS,KAAK;AACpD,QAAQ,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AACxC,QAAQ,IAAI,KAAK,EAAE;AACnB,YAAY,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/B,SAAS;AACT,QAAQ,OAAO,MAAM,CAAC;AACtB,KAAK,EAAE,EAAE,CAAC,CAAC;AACX,EAAE;AACK,SAAS,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;AACtC,IAAI,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC9C,CAAC;AACM,SAAS,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE;AACzC,IAAI,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;AAClE
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../esm/helpers.js"],"sourcesContent":["import { parseBoolean } from '@rolster/commons';\nfunction reduceErrors(errors) {\n return errors.reduce((keys, { id }) => [...keys, id], []);\n}\nexport const controlIsValid = ({ 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};\nexport const controlsAllChecked = (controls, key) => {\n return Object.values(controls).reduce((value, control) => control.disabled ? value : value && parseBoolean(control[key]), true);\n};\nexport const controlsPartialChecked = (controls, key) => {\n return Object.values(controls).reduce((value, control) => control.disabled ? value : value || parseBoolean(control[key]), false);\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 groupIsValid = ({ 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 function groupAllChecked(groups, key) {\n return groups.reduce((value, group) => value && parseBoolean(group[key]), true);\n}\nexport function groupPartialChecked(groups, key) {\n return groups.reduce((value, group) => value || parseBoolean(group[key]), false);\n}\nexport const arrayIsValid = ({ 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 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}\n//# sourceMappingURL=helpers.js.map"],"names":["parseBoolean"],"mappings":";;;;;;AACA,SAAS,YAAY,CAAC,MAAM,EAAE;AAC9B,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9D,CAAC;AACW,MAAC,cAAc,GAAG,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK;AACzD,IAAI,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,SAAS,KAAK;AACpD,QAAQ,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;AACvC,QAAQ,IAAI,KAAK,EAAE;AACnB,YAAY,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/B,SAAS;AACT,QAAQ,OAAO,MAAM,CAAC;AACtB,KAAK,EAAE,EAAE,CAAC,CAAC;AACX,EAAE;AACU,MAAC,kBAAkB,GAAG,CAAC,QAAQ,EAAE,GAAG,KAAK;AACrD,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK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,kBAAkB,CAAC,KAAK,EAAE,GAAG,EAAE;AAC/C,IAAI,OAAO,qBAAqB,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AACtD;;;;;;;;;;;;;;;"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -109,58 +109,58 @@ function someErrors(errors, keys) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
class FormControl {
|
|
112
|
-
constructor(
|
|
113
|
-
this.
|
|
114
|
-
this.
|
|
115
|
-
this.
|
|
116
|
-
this.
|
|
117
|
-
this.
|
|
118
|
-
this.
|
|
119
|
-
const
|
|
120
|
-
this.observable = commons.observable(value);
|
|
121
|
-
this.
|
|
122
|
-
this.validators = validators;
|
|
123
|
-
this.
|
|
124
|
-
this.updateValueAndValidity(value, validators);
|
|
112
|
+
constructor(options, validators) {
|
|
113
|
+
this._focused = false;
|
|
114
|
+
this._touched = false;
|
|
115
|
+
this._dirty = false;
|
|
116
|
+
this._disabled = false;
|
|
117
|
+
this._valid = true;
|
|
118
|
+
this._errors = [];
|
|
119
|
+
const _options = createFormControlOptions(options, validators);
|
|
120
|
+
this.observable = commons.observable(_options.value);
|
|
121
|
+
this.currentValue = _options.value;
|
|
122
|
+
this.validators = _options.validators;
|
|
123
|
+
this._value = _options.value;
|
|
124
|
+
this.updateValueAndValidity(_options.value, _options.validators);
|
|
125
125
|
}
|
|
126
126
|
get focused() {
|
|
127
|
-
return this.
|
|
127
|
+
return this._focused;
|
|
128
128
|
}
|
|
129
129
|
get unfocused() {
|
|
130
|
-
return !this.
|
|
130
|
+
return !this._focused;
|
|
131
131
|
}
|
|
132
132
|
get touched() {
|
|
133
|
-
return this.
|
|
133
|
+
return this._touched;
|
|
134
134
|
}
|
|
135
135
|
get untouched() {
|
|
136
|
-
return !this.
|
|
136
|
+
return !this._touched;
|
|
137
137
|
}
|
|
138
138
|
get dirty() {
|
|
139
|
-
return this.
|
|
139
|
+
return this._dirty;
|
|
140
140
|
}
|
|
141
141
|
get pristine() {
|
|
142
|
-
return !this.
|
|
142
|
+
return !this._dirty;
|
|
143
143
|
}
|
|
144
144
|
get disabled() {
|
|
145
|
-
return this.
|
|
145
|
+
return this._disabled;
|
|
146
146
|
}
|
|
147
147
|
get enabled() {
|
|
148
|
-
return !this.
|
|
148
|
+
return !this._disabled;
|
|
149
149
|
}
|
|
150
150
|
get valid() {
|
|
151
|
-
return this.
|
|
151
|
+
return this._valid;
|
|
152
152
|
}
|
|
153
153
|
get invalid() {
|
|
154
|
-
return !this.
|
|
154
|
+
return !this._valid;
|
|
155
155
|
}
|
|
156
156
|
get value() {
|
|
157
|
-
return this.
|
|
157
|
+
return this._value;
|
|
158
158
|
}
|
|
159
159
|
get errors() {
|
|
160
|
-
return this.
|
|
160
|
+
return this._errors;
|
|
161
161
|
}
|
|
162
162
|
get error() {
|
|
163
|
-
return this.
|
|
163
|
+
return this._error;
|
|
164
164
|
}
|
|
165
165
|
get wrong() {
|
|
166
166
|
return this.touched && this.invalid;
|
|
@@ -172,30 +172,34 @@ class FormControl {
|
|
|
172
172
|
return someErrors(this.errors, keys);
|
|
173
173
|
}
|
|
174
174
|
reset() {
|
|
175
|
-
this.setValue(this.
|
|
176
|
-
this.
|
|
177
|
-
this.
|
|
175
|
+
this.setValue(this.currentValue);
|
|
176
|
+
this._dirty = false;
|
|
177
|
+
this._touched = false;
|
|
178
178
|
}
|
|
179
179
|
focus() {
|
|
180
|
-
this.
|
|
180
|
+
this._focused = true;
|
|
181
181
|
}
|
|
182
182
|
blur() {
|
|
183
|
-
this.
|
|
184
|
-
this.
|
|
183
|
+
this._focused = false;
|
|
184
|
+
this._touched = true;
|
|
185
185
|
}
|
|
186
186
|
disable() {
|
|
187
|
-
this.
|
|
187
|
+
this._disabled = true;
|
|
188
188
|
}
|
|
189
189
|
enable() {
|
|
190
|
-
this.
|
|
190
|
+
this._disabled = false;
|
|
191
191
|
}
|
|
192
192
|
touch() {
|
|
193
|
-
this.
|
|
193
|
+
this._touched = true;
|
|
194
|
+
}
|
|
195
|
+
setInitialValue(value) {
|
|
196
|
+
this.currentValue = value;
|
|
197
|
+
this.setValue(value);
|
|
194
198
|
}
|
|
195
199
|
setValue(value) {
|
|
196
200
|
if (this.enabled) {
|
|
197
|
-
this.
|
|
198
|
-
this.
|
|
201
|
+
this._value = value;
|
|
202
|
+
this._dirty = true;
|
|
199
203
|
this.updateValueAndValidity(value, this.validators);
|
|
200
204
|
this.observable.next(value);
|
|
201
205
|
}
|
|
@@ -210,14 +214,14 @@ class FormControl {
|
|
|
210
214
|
updateValueAndValidity(value, validators) {
|
|
211
215
|
if (validators) {
|
|
212
216
|
const errors = controlIsValid({ value, validators });
|
|
213
|
-
this.
|
|
214
|
-
this.
|
|
215
|
-
this.
|
|
217
|
+
this._error = errors[0];
|
|
218
|
+
this._errors = errors;
|
|
219
|
+
this._valid = errors.length === 0;
|
|
216
220
|
}
|
|
217
221
|
else {
|
|
218
|
-
this.
|
|
219
|
-
this.
|
|
220
|
-
this.
|
|
222
|
+
this._valid = true;
|
|
223
|
+
this._error = undefined;
|
|
224
|
+
this._errors = [];
|
|
221
225
|
}
|
|
222
226
|
}
|
|
223
227
|
}
|
|
@@ -226,9 +230,9 @@ function formControl(options, validators) {
|
|
|
226
230
|
}
|
|
227
231
|
|
|
228
232
|
class FormArrayControl extends FormControl {
|
|
229
|
-
constructor(
|
|
230
|
-
const
|
|
231
|
-
super(value, validators);
|
|
233
|
+
constructor(options, validators) {
|
|
234
|
+
const _options = createFormControlOptions(options, validators);
|
|
235
|
+
super(_options.value, _options.validators);
|
|
232
236
|
this.uuid = uuid.v4();
|
|
233
237
|
}
|
|
234
238
|
}
|
|
@@ -237,15 +241,15 @@ function formArrayControl(options, validators) {
|
|
|
237
241
|
}
|
|
238
242
|
|
|
239
243
|
class FormGroup {
|
|
240
|
-
constructor(
|
|
241
|
-
this.
|
|
242
|
-
this.
|
|
243
|
-
const
|
|
244
|
-
this.
|
|
245
|
-
this.validators = validators;
|
|
246
|
-
this.updateValueAndValidity(controls, validators);
|
|
244
|
+
constructor(options, validators) {
|
|
245
|
+
this._errors = [];
|
|
246
|
+
this._valid = true;
|
|
247
|
+
const _options = createFormGroupOptions(options, validators);
|
|
248
|
+
this._controls = _options.controls;
|
|
249
|
+
this.validators = _options.validators;
|
|
250
|
+
this.updateValueAndValidity(_options.controls, _options.validators);
|
|
247
251
|
this.observable = commons.observable(this.value);
|
|
248
|
-
Object.values(controls).forEach((control) => {
|
|
252
|
+
Object.values(_options.controls).forEach((control) => {
|
|
249
253
|
control.subscribe(() => {
|
|
250
254
|
this.updateValueAndValidity(this.controls, this.validators);
|
|
251
255
|
this.observable.next(this.value);
|
|
@@ -253,34 +257,34 @@ class FormGroup {
|
|
|
253
257
|
});
|
|
254
258
|
}
|
|
255
259
|
get controls() {
|
|
256
|
-
return this.
|
|
260
|
+
return this._controls;
|
|
257
261
|
}
|
|
258
262
|
get touched() {
|
|
259
263
|
return controlsPartialChecked(this.controls, 'touched');
|
|
260
264
|
}
|
|
261
|
-
get
|
|
265
|
+
get toucheds() {
|
|
262
266
|
return controlsAllChecked(this.controls, 'touched');
|
|
263
267
|
}
|
|
264
268
|
get untouched() {
|
|
265
269
|
return !this.touched;
|
|
266
270
|
}
|
|
267
|
-
get
|
|
268
|
-
return !this.
|
|
271
|
+
get untoucheds() {
|
|
272
|
+
return !this.toucheds;
|
|
269
273
|
}
|
|
270
274
|
get dirty() {
|
|
271
275
|
return controlsPartialChecked(this.controls, 'dirty');
|
|
272
276
|
}
|
|
273
|
-
get
|
|
277
|
+
get dirties() {
|
|
274
278
|
return controlsAllChecked(this.controls, 'dirty');
|
|
275
279
|
}
|
|
276
280
|
get pristine() {
|
|
277
281
|
return !this.dirty;
|
|
278
282
|
}
|
|
279
|
-
get
|
|
280
|
-
return this.
|
|
283
|
+
get pristines() {
|
|
284
|
+
return this.dirties;
|
|
281
285
|
}
|
|
282
286
|
get valid() {
|
|
283
|
-
return this.
|
|
287
|
+
return this._valid && controlsAllChecked(this.controls, 'valid');
|
|
284
288
|
}
|
|
285
289
|
get invalid() {
|
|
286
290
|
return !this.valid;
|
|
@@ -289,10 +293,10 @@ class FormGroup {
|
|
|
289
293
|
return controlsToValue(this.controls);
|
|
290
294
|
}
|
|
291
295
|
get errors() {
|
|
292
|
-
return this.
|
|
296
|
+
return this._errors;
|
|
293
297
|
}
|
|
294
298
|
get error() {
|
|
295
|
-
return this.
|
|
299
|
+
return this._error;
|
|
296
300
|
}
|
|
297
301
|
get wrong() {
|
|
298
302
|
return this.touched && this.invalid;
|
|
@@ -312,14 +316,14 @@ class FormGroup {
|
|
|
312
316
|
updateValueAndValidity(controls, validators) {
|
|
313
317
|
if (validators) {
|
|
314
318
|
const errors = groupIsValid({ controls, validators });
|
|
315
|
-
this.
|
|
316
|
-
this.
|
|
317
|
-
this.
|
|
319
|
+
this._errors = errors;
|
|
320
|
+
this._error = errors[0];
|
|
321
|
+
this._valid = errors.length === 0;
|
|
318
322
|
}
|
|
319
323
|
else {
|
|
320
|
-
this.
|
|
321
|
-
this.
|
|
322
|
-
this.
|
|
324
|
+
this._errors = [];
|
|
325
|
+
this._error = undefined;
|
|
326
|
+
this._valid = true;
|
|
323
327
|
}
|
|
324
328
|
}
|
|
325
329
|
}
|
|
@@ -328,11 +332,11 @@ function formGroup(options, validators) {
|
|
|
328
332
|
}
|
|
329
333
|
|
|
330
334
|
class FormArrayGroup extends FormGroup {
|
|
331
|
-
constructor(
|
|
332
|
-
const
|
|
333
|
-
super(controls, validators);
|
|
335
|
+
constructor(options, validators) {
|
|
336
|
+
const _options = createFormGroupOptions(options, validators);
|
|
337
|
+
super(_options.controls, _options.validators);
|
|
334
338
|
this.uuid = uuid.v4();
|
|
335
|
-
this.resource = resource;
|
|
339
|
+
this.resource = _options.resource;
|
|
336
340
|
}
|
|
337
341
|
}
|
|
338
342
|
function formArrayGroup(options, validators) {
|
|
@@ -341,14 +345,14 @@ function formArrayGroup(options, validators) {
|
|
|
341
345
|
|
|
342
346
|
class FormArrayList extends FormControl {
|
|
343
347
|
constructor(valueToControls, value, validators) {
|
|
344
|
-
const
|
|
345
|
-
super(
|
|
348
|
+
const _value = value || [];
|
|
349
|
+
super(_value, validators);
|
|
346
350
|
this.valueToControls = valueToControls;
|
|
347
|
-
this.
|
|
351
|
+
this._controls = _value.map((value) => this.createControls(value));
|
|
348
352
|
this.uuid = uuid.v4();
|
|
349
353
|
}
|
|
350
354
|
get controls() {
|
|
351
|
-
return this.
|
|
355
|
+
return this._controls;
|
|
352
356
|
}
|
|
353
357
|
get touched() {
|
|
354
358
|
return this.controls.reduce((valid, controls) => valid && controlsPartialChecked(controls, 'touched'), true);
|
|
@@ -357,20 +361,20 @@ class FormArrayList extends FormControl {
|
|
|
357
361
|
return this.controls.reduce((valid, controls) => valid && controlsPartialChecked(controls, 'dirty'), true);
|
|
358
362
|
}
|
|
359
363
|
get valid() {
|
|
360
|
-
return (this.
|
|
364
|
+
return (this._valid &&
|
|
361
365
|
this.controls.reduce((valid, controls) => valid && controlsAllChecked(controls, 'valid'), true));
|
|
362
366
|
}
|
|
363
367
|
get value() {
|
|
364
368
|
return this.controls.map((controls) => controlsToValue(controls));
|
|
365
369
|
}
|
|
366
370
|
setValue(values) {
|
|
367
|
-
this.
|
|
371
|
+
this._controls = values.map((value) => this.createControls(value));
|
|
368
372
|
}
|
|
369
373
|
push(controls) {
|
|
370
|
-
this.
|
|
374
|
+
this._controls = this._controls.concat([controls]);
|
|
371
375
|
}
|
|
372
376
|
remove(controls) {
|
|
373
|
-
this.
|
|
377
|
+
this._controls = this._controls.filter((_controls) => _controls !== controls);
|
|
374
378
|
}
|
|
375
379
|
createControls(value) {
|
|
376
380
|
const controls = this.valueToControls(value);
|
|
@@ -389,23 +393,23 @@ function formArrayList(valueToControl, value, validators) {
|
|
|
389
393
|
}
|
|
390
394
|
|
|
391
395
|
class FormArray {
|
|
392
|
-
constructor(
|
|
393
|
-
this.
|
|
394
|
-
this.
|
|
395
|
-
this.
|
|
396
|
-
this.
|
|
397
|
-
const
|
|
396
|
+
constructor(options, validators) {
|
|
397
|
+
this._groups = [];
|
|
398
|
+
this._valid = true;
|
|
399
|
+
this._disabled = false;
|
|
400
|
+
this._errors = [];
|
|
401
|
+
const _options = createFormArrayOptions(options, validators);
|
|
398
402
|
this.unsusbcriptions = new Map();
|
|
399
|
-
this.
|
|
400
|
-
this.validators = validators;
|
|
401
|
-
this.refresh(this.
|
|
403
|
+
this.currentValue = _options.groups;
|
|
404
|
+
this.validators = _options.validators;
|
|
405
|
+
this.refresh(this.currentValue);
|
|
402
406
|
this.observable = commons.observable(this.value);
|
|
403
|
-
groups?.forEach((group) => {
|
|
407
|
+
_options.groups?.forEach((group) => {
|
|
404
408
|
this.subscription(group);
|
|
405
409
|
});
|
|
406
410
|
}
|
|
407
411
|
get groups() {
|
|
408
|
-
return this.
|
|
412
|
+
return this._groups;
|
|
409
413
|
}
|
|
410
414
|
get controls() {
|
|
411
415
|
return this.groups.map(({ controls }) => controls);
|
|
@@ -413,47 +417,47 @@ class FormArray {
|
|
|
413
417
|
get touched() {
|
|
414
418
|
return groupPartialChecked(this.groups, 'touched');
|
|
415
419
|
}
|
|
416
|
-
get
|
|
417
|
-
return groupAllChecked(this.groups, '
|
|
420
|
+
get toucheds() {
|
|
421
|
+
return groupAllChecked(this.groups, 'toucheds');
|
|
418
422
|
}
|
|
419
423
|
get untouched() {
|
|
420
424
|
return !this.touched;
|
|
421
425
|
}
|
|
422
|
-
get
|
|
423
|
-
return !this.
|
|
426
|
+
get untoucheds() {
|
|
427
|
+
return !this.toucheds;
|
|
424
428
|
}
|
|
425
429
|
get dirty() {
|
|
426
430
|
return groupPartialChecked(this.groups, 'dirty');
|
|
427
431
|
}
|
|
428
|
-
get
|
|
429
|
-
return groupAllChecked(this.groups, '
|
|
432
|
+
get dirties() {
|
|
433
|
+
return groupAllChecked(this.groups, 'dirties');
|
|
430
434
|
}
|
|
431
435
|
get pristine() {
|
|
432
436
|
return !this.dirty;
|
|
433
437
|
}
|
|
434
|
-
get
|
|
435
|
-
return !this.
|
|
438
|
+
get pristines() {
|
|
439
|
+
return !this.dirties;
|
|
436
440
|
}
|
|
437
441
|
get disabled() {
|
|
438
|
-
return this.
|
|
442
|
+
return this._disabled;
|
|
439
443
|
}
|
|
440
444
|
get enabled() {
|
|
441
|
-
return !this.
|
|
445
|
+
return !this._disabled;
|
|
442
446
|
}
|
|
443
447
|
get valid() {
|
|
444
|
-
return this.
|
|
448
|
+
return this._valid && groupAllChecked(this.groups, 'valid');
|
|
445
449
|
}
|
|
446
450
|
get invalid() {
|
|
447
|
-
return !this.
|
|
451
|
+
return !this._valid;
|
|
448
452
|
}
|
|
449
453
|
get value() {
|
|
450
454
|
return this.groups.map(({ value: state }) => state);
|
|
451
455
|
}
|
|
452
456
|
get error() {
|
|
453
|
-
return this.
|
|
457
|
+
return this._error;
|
|
454
458
|
}
|
|
455
459
|
get errors() {
|
|
456
|
-
return this.
|
|
460
|
+
return this._errors;
|
|
457
461
|
}
|
|
458
462
|
get wrong() {
|
|
459
463
|
return this.touched && this.invalid;
|
|
@@ -465,13 +469,13 @@ class FormArray {
|
|
|
465
469
|
return someErrors(this.errors, keys);
|
|
466
470
|
}
|
|
467
471
|
reset() {
|
|
468
|
-
this.refresh(this.
|
|
472
|
+
this.refresh(this.currentValue);
|
|
469
473
|
}
|
|
470
474
|
disable() {
|
|
471
|
-
this.
|
|
475
|
+
this._disabled = true;
|
|
472
476
|
}
|
|
473
477
|
enable() {
|
|
474
|
-
this.
|
|
478
|
+
this._disabled = false;
|
|
475
479
|
}
|
|
476
480
|
push(group) {
|
|
477
481
|
this.subscription(group);
|
|
@@ -483,8 +487,12 @@ class FormArray {
|
|
|
483
487
|
});
|
|
484
488
|
this.refresh([...this.groups, ...groups]);
|
|
485
489
|
}
|
|
486
|
-
|
|
487
|
-
this.
|
|
490
|
+
setInitialValue(groups) {
|
|
491
|
+
this.currentValue = groups;
|
|
492
|
+
this.setValue(groups);
|
|
493
|
+
}
|
|
494
|
+
setValue(groups) {
|
|
495
|
+
this._groups.forEach(({ uuid }) => {
|
|
488
496
|
this.unsusbcriptions.delete(uuid);
|
|
489
497
|
});
|
|
490
498
|
groups.forEach((group) => {
|
|
@@ -511,19 +519,19 @@ class FormArray {
|
|
|
511
519
|
updateValidityStatus(groups, validators) {
|
|
512
520
|
if (validators) {
|
|
513
521
|
const errors = arrayIsValid({ groups, validators });
|
|
514
|
-
this.
|
|
515
|
-
this.
|
|
516
|
-
this.
|
|
522
|
+
this._errors = errors;
|
|
523
|
+
this._error = errors[0];
|
|
524
|
+
this._valid = errors.length === 0;
|
|
517
525
|
}
|
|
518
526
|
else {
|
|
519
|
-
this.
|
|
520
|
-
this.
|
|
521
|
-
this.
|
|
527
|
+
this._valid = true;
|
|
528
|
+
this._errors = [];
|
|
529
|
+
this._error = undefined;
|
|
522
530
|
}
|
|
523
531
|
}
|
|
524
532
|
refresh(newGroups) {
|
|
525
533
|
const groups = newGroups || [];
|
|
526
|
-
this.
|
|
534
|
+
this._groups = groups;
|
|
527
535
|
this.updateValidityStatus(groups, this.validators);
|
|
528
536
|
}
|
|
529
537
|
}
|