@rolster/forms 2.9.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 +120 -120
- 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 +120 -120
- 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 +10 -10
- package/dist/esm/form-array/form-array.js +37 -37
- package/dist/esm/form-array/form-array.js.map +1 -1
- package/dist/esm/form-control.d.ts +9 -9
- package/dist/esm/form-control.js +44 -44
- 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 +8 -8
- package/package.json +1 -1
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,34 +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
194
|
}
|
|
195
195
|
setInitialValue(value) {
|
|
196
|
-
this.
|
|
196
|
+
this.currentValue = value;
|
|
197
197
|
this.setValue(value);
|
|
198
198
|
}
|
|
199
199
|
setValue(value) {
|
|
200
200
|
if (this.enabled) {
|
|
201
|
-
this.
|
|
202
|
-
this.
|
|
201
|
+
this._value = value;
|
|
202
|
+
this._dirty = true;
|
|
203
203
|
this.updateValueAndValidity(value, this.validators);
|
|
204
204
|
this.observable.next(value);
|
|
205
205
|
}
|
|
@@ -214,14 +214,14 @@ class FormControl {
|
|
|
214
214
|
updateValueAndValidity(value, validators) {
|
|
215
215
|
if (validators) {
|
|
216
216
|
const errors = controlIsValid({ value, validators });
|
|
217
|
-
this.
|
|
218
|
-
this.
|
|
219
|
-
this.
|
|
217
|
+
this._error = errors[0];
|
|
218
|
+
this._errors = errors;
|
|
219
|
+
this._valid = errors.length === 0;
|
|
220
220
|
}
|
|
221
221
|
else {
|
|
222
|
-
this.
|
|
223
|
-
this.
|
|
224
|
-
this.
|
|
222
|
+
this._valid = true;
|
|
223
|
+
this._error = undefined;
|
|
224
|
+
this._errors = [];
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
}
|
|
@@ -230,9 +230,9 @@ function formControl(options, validators) {
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
class FormArrayControl extends FormControl {
|
|
233
|
-
constructor(
|
|
234
|
-
const
|
|
235
|
-
super(value, validators);
|
|
233
|
+
constructor(options, validators) {
|
|
234
|
+
const _options = createFormControlOptions(options, validators);
|
|
235
|
+
super(_options.value, _options.validators);
|
|
236
236
|
this.uuid = uuid.v4();
|
|
237
237
|
}
|
|
238
238
|
}
|
|
@@ -241,15 +241,15 @@ function formArrayControl(options, validators) {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
class FormGroup {
|
|
244
|
-
constructor(
|
|
245
|
-
this.
|
|
246
|
-
this.
|
|
247
|
-
const
|
|
248
|
-
this.
|
|
249
|
-
this.validators = validators;
|
|
250
|
-
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);
|
|
251
251
|
this.observable = commons.observable(this.value);
|
|
252
|
-
Object.values(controls).forEach((control) => {
|
|
252
|
+
Object.values(_options.controls).forEach((control) => {
|
|
253
253
|
control.subscribe(() => {
|
|
254
254
|
this.updateValueAndValidity(this.controls, this.validators);
|
|
255
255
|
this.observable.next(this.value);
|
|
@@ -257,34 +257,34 @@ class FormGroup {
|
|
|
257
257
|
});
|
|
258
258
|
}
|
|
259
259
|
get controls() {
|
|
260
|
-
return this.
|
|
260
|
+
return this._controls;
|
|
261
261
|
}
|
|
262
262
|
get touched() {
|
|
263
263
|
return controlsPartialChecked(this.controls, 'touched');
|
|
264
264
|
}
|
|
265
|
-
get
|
|
265
|
+
get toucheds() {
|
|
266
266
|
return controlsAllChecked(this.controls, 'touched');
|
|
267
267
|
}
|
|
268
268
|
get untouched() {
|
|
269
269
|
return !this.touched;
|
|
270
270
|
}
|
|
271
|
-
get
|
|
272
|
-
return !this.
|
|
271
|
+
get untoucheds() {
|
|
272
|
+
return !this.toucheds;
|
|
273
273
|
}
|
|
274
274
|
get dirty() {
|
|
275
275
|
return controlsPartialChecked(this.controls, 'dirty');
|
|
276
276
|
}
|
|
277
|
-
get
|
|
277
|
+
get dirties() {
|
|
278
278
|
return controlsAllChecked(this.controls, 'dirty');
|
|
279
279
|
}
|
|
280
280
|
get pristine() {
|
|
281
281
|
return !this.dirty;
|
|
282
282
|
}
|
|
283
|
-
get
|
|
284
|
-
return this.
|
|
283
|
+
get pristines() {
|
|
284
|
+
return this.dirties;
|
|
285
285
|
}
|
|
286
286
|
get valid() {
|
|
287
|
-
return this.
|
|
287
|
+
return this._valid && controlsAllChecked(this.controls, 'valid');
|
|
288
288
|
}
|
|
289
289
|
get invalid() {
|
|
290
290
|
return !this.valid;
|
|
@@ -293,10 +293,10 @@ class FormGroup {
|
|
|
293
293
|
return controlsToValue(this.controls);
|
|
294
294
|
}
|
|
295
295
|
get errors() {
|
|
296
|
-
return this.
|
|
296
|
+
return this._errors;
|
|
297
297
|
}
|
|
298
298
|
get error() {
|
|
299
|
-
return this.
|
|
299
|
+
return this._error;
|
|
300
300
|
}
|
|
301
301
|
get wrong() {
|
|
302
302
|
return this.touched && this.invalid;
|
|
@@ -316,14 +316,14 @@ class FormGroup {
|
|
|
316
316
|
updateValueAndValidity(controls, validators) {
|
|
317
317
|
if (validators) {
|
|
318
318
|
const errors = groupIsValid({ controls, validators });
|
|
319
|
-
this.
|
|
320
|
-
this.
|
|
321
|
-
this.
|
|
319
|
+
this._errors = errors;
|
|
320
|
+
this._error = errors[0];
|
|
321
|
+
this._valid = errors.length === 0;
|
|
322
322
|
}
|
|
323
323
|
else {
|
|
324
|
-
this.
|
|
325
|
-
this.
|
|
326
|
-
this.
|
|
324
|
+
this._errors = [];
|
|
325
|
+
this._error = undefined;
|
|
326
|
+
this._valid = true;
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
}
|
|
@@ -332,11 +332,11 @@ function formGroup(options, validators) {
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
class FormArrayGroup extends FormGroup {
|
|
335
|
-
constructor(
|
|
336
|
-
const
|
|
337
|
-
super(controls, validators);
|
|
335
|
+
constructor(options, validators) {
|
|
336
|
+
const _options = createFormGroupOptions(options, validators);
|
|
337
|
+
super(_options.controls, _options.validators);
|
|
338
338
|
this.uuid = uuid.v4();
|
|
339
|
-
this.resource = resource;
|
|
339
|
+
this.resource = _options.resource;
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
function formArrayGroup(options, validators) {
|
|
@@ -345,14 +345,14 @@ function formArrayGroup(options, validators) {
|
|
|
345
345
|
|
|
346
346
|
class FormArrayList extends FormControl {
|
|
347
347
|
constructor(valueToControls, value, validators) {
|
|
348
|
-
const
|
|
349
|
-
super(
|
|
348
|
+
const _value = value || [];
|
|
349
|
+
super(_value, validators);
|
|
350
350
|
this.valueToControls = valueToControls;
|
|
351
|
-
this.
|
|
351
|
+
this._controls = _value.map((value) => this.createControls(value));
|
|
352
352
|
this.uuid = uuid.v4();
|
|
353
353
|
}
|
|
354
354
|
get controls() {
|
|
355
|
-
return this.
|
|
355
|
+
return this._controls;
|
|
356
356
|
}
|
|
357
357
|
get touched() {
|
|
358
358
|
return this.controls.reduce((valid, controls) => valid && controlsPartialChecked(controls, 'touched'), true);
|
|
@@ -361,20 +361,20 @@ class FormArrayList extends FormControl {
|
|
|
361
361
|
return this.controls.reduce((valid, controls) => valid && controlsPartialChecked(controls, 'dirty'), true);
|
|
362
362
|
}
|
|
363
363
|
get valid() {
|
|
364
|
-
return (this.
|
|
364
|
+
return (this._valid &&
|
|
365
365
|
this.controls.reduce((valid, controls) => valid && controlsAllChecked(controls, 'valid'), true));
|
|
366
366
|
}
|
|
367
367
|
get value() {
|
|
368
368
|
return this.controls.map((controls) => controlsToValue(controls));
|
|
369
369
|
}
|
|
370
370
|
setValue(values) {
|
|
371
|
-
this.
|
|
371
|
+
this._controls = values.map((value) => this.createControls(value));
|
|
372
372
|
}
|
|
373
373
|
push(controls) {
|
|
374
|
-
this.
|
|
374
|
+
this._controls = this._controls.concat([controls]);
|
|
375
375
|
}
|
|
376
376
|
remove(controls) {
|
|
377
|
-
this.
|
|
377
|
+
this._controls = this._controls.filter((_controls) => _controls !== controls);
|
|
378
378
|
}
|
|
379
379
|
createControls(value) {
|
|
380
380
|
const controls = this.valueToControls(value);
|
|
@@ -393,23 +393,23 @@ function formArrayList(valueToControl, value, validators) {
|
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
class FormArray {
|
|
396
|
-
constructor(
|
|
397
|
-
this.
|
|
398
|
-
this.
|
|
399
|
-
this.
|
|
400
|
-
this.
|
|
401
|
-
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);
|
|
402
402
|
this.unsusbcriptions = new Map();
|
|
403
|
-
this.
|
|
404
|
-
this.validators = validators;
|
|
405
|
-
this.refresh(this.
|
|
403
|
+
this.currentValue = _options.groups;
|
|
404
|
+
this.validators = _options.validators;
|
|
405
|
+
this.refresh(this.currentValue);
|
|
406
406
|
this.observable = commons.observable(this.value);
|
|
407
|
-
groups?.forEach((group) => {
|
|
407
|
+
_options.groups?.forEach((group) => {
|
|
408
408
|
this.subscription(group);
|
|
409
409
|
});
|
|
410
410
|
}
|
|
411
411
|
get groups() {
|
|
412
|
-
return this.
|
|
412
|
+
return this._groups;
|
|
413
413
|
}
|
|
414
414
|
get controls() {
|
|
415
415
|
return this.groups.map(({ controls }) => controls);
|
|
@@ -417,47 +417,47 @@ class FormArray {
|
|
|
417
417
|
get touched() {
|
|
418
418
|
return groupPartialChecked(this.groups, 'touched');
|
|
419
419
|
}
|
|
420
|
-
get
|
|
421
|
-
return groupAllChecked(this.groups, '
|
|
420
|
+
get toucheds() {
|
|
421
|
+
return groupAllChecked(this.groups, 'toucheds');
|
|
422
422
|
}
|
|
423
423
|
get untouched() {
|
|
424
424
|
return !this.touched;
|
|
425
425
|
}
|
|
426
|
-
get
|
|
427
|
-
return !this.
|
|
426
|
+
get untoucheds() {
|
|
427
|
+
return !this.toucheds;
|
|
428
428
|
}
|
|
429
429
|
get dirty() {
|
|
430
430
|
return groupPartialChecked(this.groups, 'dirty');
|
|
431
431
|
}
|
|
432
|
-
get
|
|
433
|
-
return groupAllChecked(this.groups, '
|
|
432
|
+
get dirties() {
|
|
433
|
+
return groupAllChecked(this.groups, 'dirties');
|
|
434
434
|
}
|
|
435
435
|
get pristine() {
|
|
436
436
|
return !this.dirty;
|
|
437
437
|
}
|
|
438
|
-
get
|
|
439
|
-
return !this.
|
|
438
|
+
get pristines() {
|
|
439
|
+
return !this.dirties;
|
|
440
440
|
}
|
|
441
441
|
get disabled() {
|
|
442
|
-
return this.
|
|
442
|
+
return this._disabled;
|
|
443
443
|
}
|
|
444
444
|
get enabled() {
|
|
445
|
-
return !this.
|
|
445
|
+
return !this._disabled;
|
|
446
446
|
}
|
|
447
447
|
get valid() {
|
|
448
|
-
return this.
|
|
448
|
+
return this._valid && groupAllChecked(this.groups, 'valid');
|
|
449
449
|
}
|
|
450
450
|
get invalid() {
|
|
451
|
-
return !this.
|
|
451
|
+
return !this._valid;
|
|
452
452
|
}
|
|
453
453
|
get value() {
|
|
454
454
|
return this.groups.map(({ value: state }) => state);
|
|
455
455
|
}
|
|
456
456
|
get error() {
|
|
457
|
-
return this.
|
|
457
|
+
return this._error;
|
|
458
458
|
}
|
|
459
459
|
get errors() {
|
|
460
|
-
return this.
|
|
460
|
+
return this._errors;
|
|
461
461
|
}
|
|
462
462
|
get wrong() {
|
|
463
463
|
return this.touched && this.invalid;
|
|
@@ -469,13 +469,13 @@ class FormArray {
|
|
|
469
469
|
return someErrors(this.errors, keys);
|
|
470
470
|
}
|
|
471
471
|
reset() {
|
|
472
|
-
this.refresh(this.
|
|
472
|
+
this.refresh(this.currentValue);
|
|
473
473
|
}
|
|
474
474
|
disable() {
|
|
475
|
-
this.
|
|
475
|
+
this._disabled = true;
|
|
476
476
|
}
|
|
477
477
|
enable() {
|
|
478
|
-
this.
|
|
478
|
+
this._disabled = false;
|
|
479
479
|
}
|
|
480
480
|
push(group) {
|
|
481
481
|
this.subscription(group);
|
|
@@ -488,11 +488,11 @@ class FormArray {
|
|
|
488
488
|
this.refresh([...this.groups, ...groups]);
|
|
489
489
|
}
|
|
490
490
|
setInitialValue(groups) {
|
|
491
|
-
this.
|
|
491
|
+
this.currentValue = groups;
|
|
492
492
|
this.setValue(groups);
|
|
493
493
|
}
|
|
494
494
|
setValue(groups) {
|
|
495
|
-
this.
|
|
495
|
+
this._groups.forEach(({ uuid }) => {
|
|
496
496
|
this.unsusbcriptions.delete(uuid);
|
|
497
497
|
});
|
|
498
498
|
groups.forEach((group) => {
|
|
@@ -519,19 +519,19 @@ class FormArray {
|
|
|
519
519
|
updateValidityStatus(groups, validators) {
|
|
520
520
|
if (validators) {
|
|
521
521
|
const errors = arrayIsValid({ groups, validators });
|
|
522
|
-
this.
|
|
523
|
-
this.
|
|
524
|
-
this.
|
|
522
|
+
this._errors = errors;
|
|
523
|
+
this._error = errors[0];
|
|
524
|
+
this._valid = errors.length === 0;
|
|
525
525
|
}
|
|
526
526
|
else {
|
|
527
|
-
this.
|
|
528
|
-
this.
|
|
529
|
-
this.
|
|
527
|
+
this._valid = true;
|
|
528
|
+
this._errors = [];
|
|
529
|
+
this._error = undefined;
|
|
530
530
|
}
|
|
531
531
|
}
|
|
532
532
|
refresh(newGroups) {
|
|
533
533
|
const groups = newGroups || [];
|
|
534
|
-
this.
|
|
534
|
+
this._groups = groups;
|
|
535
535
|
this.updateValidityStatus(groups, this.validators);
|
|
536
536
|
}
|
|
537
537
|
}
|