@rxap/forms 13.0.0 → 13.0.2
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/esm2020/lib/form-array.mjs +31 -11
- package/esm2020/lib/form-group.mjs +17 -3
- package/esm2020/lib/types.mjs +1 -1
- package/fesm2015/rxap-forms.mjs +46 -12
- package/fesm2015/rxap-forms.mjs.map +1 -1
- package/fesm2020/rxap-forms.mjs +46 -12
- package/fesm2020/rxap-forms.mjs.map +1 -1
- package/lib/form-array.d.ts +5 -3
- package/lib/form-group.d.ts +1 -0
- package/lib/types.d.ts +8 -1
- package/package.json +4 -4
package/fesm2020/rxap-forms.mjs
CHANGED
|
@@ -170,8 +170,9 @@ class RxapFormArray extends FormArray {
|
|
|
170
170
|
*
|
|
171
171
|
* @param index (optional) the index where the control should be created
|
|
172
172
|
* @param state (optional) the initial state of the new control
|
|
173
|
+
* @param options (optional) ControlEventOptions
|
|
173
174
|
*/
|
|
174
|
-
insertAt(index, state) {
|
|
175
|
+
insertAt(index, state, options) {
|
|
175
176
|
const insertIndex = index ?? this.controls.length;
|
|
176
177
|
const controlOrDefinition = this._builder(state, {
|
|
177
178
|
controlId: insertIndex.toFixed(0),
|
|
@@ -186,10 +187,10 @@ class RxapFormArray extends FormArray {
|
|
|
186
187
|
// call the super insert after the update, bc the insert method will
|
|
187
188
|
// trigger a change detection
|
|
188
189
|
if (controlOrDefinition instanceof AbstractControl) {
|
|
189
|
-
super.insert(insertIndex, controlOrDefinition);
|
|
190
|
+
super.insert(insertIndex, controlOrDefinition, options);
|
|
190
191
|
}
|
|
191
192
|
else {
|
|
192
|
-
super.insert(insertIndex, controlOrDefinition.rxapFormGroup);
|
|
193
|
+
super.insert(insertIndex, controlOrDefinition.rxapFormGroup, options);
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
disabledWhile(observable, options) {
|
|
@@ -216,7 +217,9 @@ class RxapFormArray extends FormArray {
|
|
|
216
217
|
}
|
|
217
218
|
setValue(valueOrObservable, options) {
|
|
218
219
|
if (isObservable(valueOrObservable)) {
|
|
219
|
-
return valueOrObservable.subscribe((value) =>
|
|
220
|
+
return valueOrObservable.subscribe((value) => {
|
|
221
|
+
super.setValue(value, options);
|
|
222
|
+
});
|
|
220
223
|
}
|
|
221
224
|
super.setValue(valueOrObservable, options);
|
|
222
225
|
}
|
|
@@ -231,13 +234,30 @@ class RxapFormArray extends FormArray {
|
|
|
231
234
|
hasErrorAndTouched(errorCode, path) {
|
|
232
235
|
return hasErrorAndTouched(this, errorCode, path);
|
|
233
236
|
}
|
|
237
|
+
_patchValue(value, options) {
|
|
238
|
+
// Even though the `value` argument type doesn't allow `null` and `undefined` values, the
|
|
239
|
+
// `patchValue` can be called recursively and inner data structures might have these values, so
|
|
240
|
+
// we just ignore such cases when a field containing FormArray instance receives `null` or
|
|
241
|
+
// `undefined` as a value.
|
|
242
|
+
if (value == null /* both `null` and `undefined` */)
|
|
243
|
+
return;
|
|
244
|
+
value.forEach((newValue, index) => {
|
|
245
|
+
if (this.at(index)) {
|
|
246
|
+
this.at(index).patchValue(newValue, { ...(options ?? {}), onlySelf: true });
|
|
247
|
+
}
|
|
248
|
+
else if (options?.coerce) {
|
|
249
|
+
this.insertAt(index, value[index]);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
this.updateValueAndValidity(options);
|
|
253
|
+
}
|
|
234
254
|
patchValue(valueOrObservable, options) {
|
|
235
255
|
if (isObservable(valueOrObservable)) {
|
|
236
256
|
return valueOrObservable.subscribe((value) => {
|
|
237
|
-
|
|
257
|
+
this._patchValue(value, options);
|
|
238
258
|
});
|
|
239
259
|
}
|
|
240
|
-
|
|
260
|
+
this._patchValue(valueOrObservable, options);
|
|
241
261
|
}
|
|
242
262
|
hasErrorAndDirty(errorCode, path) {
|
|
243
263
|
return hasErrorAndDirty(this, errorCode, path);
|
|
@@ -252,20 +272,20 @@ class RxapFormArray extends FormArray {
|
|
|
252
272
|
setEnable(enable = true, opts) {
|
|
253
273
|
enableControl(this, enable, opts);
|
|
254
274
|
}
|
|
255
|
-
push(control) {
|
|
275
|
+
push(control, options) {
|
|
256
276
|
if (isDevMode()) {
|
|
257
277
|
console.warn('It is not recommend to use the FormArray.push method');
|
|
258
278
|
}
|
|
259
|
-
return super.push(control);
|
|
279
|
+
return super.push(control, options);
|
|
260
280
|
}
|
|
261
281
|
setDisable(disable = true, opts) {
|
|
262
282
|
disableControl(this, disable, opts);
|
|
263
283
|
}
|
|
264
|
-
setControl(index, control) {
|
|
284
|
+
setControl(index, control, options) {
|
|
265
285
|
if (isDevMode()) {
|
|
266
286
|
console.warn('It is not recommend to use the FormArray.setControl method');
|
|
267
287
|
}
|
|
268
|
-
return super.setControl(index, control);
|
|
288
|
+
return super.setControl(index, control, options);
|
|
269
289
|
}
|
|
270
290
|
markAsTouched(opts) {
|
|
271
291
|
super.markAsTouched(opts);
|
|
@@ -409,11 +429,25 @@ class RxapFormGroup extends FormGroup {
|
|
|
409
429
|
}
|
|
410
430
|
super.setValue(valueOrObservable, options);
|
|
411
431
|
}
|
|
432
|
+
_patchValue(value, options) {
|
|
433
|
+
// Even though the `value` argument type doesn't allow `null` and `undefined` values, the
|
|
434
|
+
// `patchValue` can be called recursively and inner data structures might have these values, so
|
|
435
|
+
// we just ignore such cases when a field containing FormGroup instance receives `null` or
|
|
436
|
+
// `undefined` as a value.
|
|
437
|
+
if (value == null /* both `null` and `undefined` */)
|
|
438
|
+
return;
|
|
439
|
+
Object.keys(value).forEach(name => {
|
|
440
|
+
if (this.controls[name]) {
|
|
441
|
+
this.controls[name].patchValue(value[name], { ...(options ?? {}), onlySelf: true });
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
this.updateValueAndValidity(options);
|
|
445
|
+
}
|
|
412
446
|
patchValue(valueOrObservable, options) {
|
|
413
447
|
if (isObservable(valueOrObservable)) {
|
|
414
|
-
return valueOrObservable.subscribe((value) =>
|
|
448
|
+
return valueOrObservable.subscribe((value) => this._patchValue(value, options));
|
|
415
449
|
}
|
|
416
|
-
|
|
450
|
+
this._patchValue(valueOrObservable, options);
|
|
417
451
|
}
|
|
418
452
|
disabledWhile(observable, options) {
|
|
419
453
|
return controlDisabledWhile(this, observable, options);
|