@rxap/forms 13.0.1 → 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.
@@ -215,25 +215,12 @@ class RxapFormArray extends FormArray {
215
215
  markAllAsPristine() {
216
216
  markAllPristine(this);
217
217
  }
218
- coerceValue(value) {
219
- for (let index = 0; index < value.length; index++) {
220
- if (!this.at(index)) {
221
- this.insertAt(index, value[index]);
222
- }
223
- }
224
- }
225
218
  setValue(valueOrObservable, options) {
226
219
  if (isObservable(valueOrObservable)) {
227
220
  return valueOrObservable.subscribe((value) => {
228
- if (options?.coerce) {
229
- this.coerceValue(value);
230
- }
231
221
  super.setValue(value, options);
232
222
  });
233
223
  }
234
- if (options?.coerce) {
235
- this.coerceValue(valueOrObservable);
236
- }
237
224
  super.setValue(valueOrObservable, options);
238
225
  }
239
226
  markAllAsUntouched() {
@@ -247,19 +234,30 @@ class RxapFormArray extends FormArray {
247
234
  hasErrorAndTouched(errorCode, path) {
248
235
  return hasErrorAndTouched(this, errorCode, path);
249
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
+ }
250
254
  patchValue(valueOrObservable, options) {
251
255
  if (isObservable(valueOrObservable)) {
252
256
  return valueOrObservable.subscribe((value) => {
253
- if (options?.coerce) {
254
- this.coerceValue(value);
255
- }
256
- super.patchValue(value, options);
257
+ this._patchValue(value, options);
257
258
  });
258
259
  }
259
- if (options?.coerce) {
260
- this.coerceValue(valueOrObservable);
261
- }
262
- super.patchValue(valueOrObservable, options);
260
+ this._patchValue(valueOrObservable, options);
263
261
  }
264
262
  hasErrorAndDirty(errorCode, path) {
265
263
  return hasErrorAndDirty(this, errorCode, path);
@@ -431,11 +429,25 @@ class RxapFormGroup extends FormGroup {
431
429
  }
432
430
  super.setValue(valueOrObservable, options);
433
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
+ }
434
446
  patchValue(valueOrObservable, options) {
435
447
  if (isObservable(valueOrObservable)) {
436
- return valueOrObservable.subscribe((value) => super.patchValue(value, options));
448
+ return valueOrObservable.subscribe((value) => this._patchValue(value, options));
437
449
  }
438
- super.patchValue(valueOrObservable, options);
450
+ this._patchValue(valueOrObservable, options);
439
451
  }
440
452
  disabledWhile(observable, options) {
441
453
  return controlDisabledWhile(this, observable, options);