Verified Commit cb73bac8 authored by Merzough Münker's avatar Merzough Münker
Browse files

fix(form-array): improve removeAt logic to handle validations

Enhance `removeAt` method to ensure appropriate updates to controls and validations when removal logic is impacted by `controlRemovedFn`. Added support for controllable event emission through `opts`.
parent 64b769b2
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -321,12 +321,17 @@ export class RxapFormArray<T = any,
    return hasErrorAndDirty(this, errorCode, path);
  }

  public override removeAt(index: number) {
  public override removeAt(index: number, opts?: ControlEventOptions) {
    if (isDevMode()) {
      console.warn('It is not recommend to use the FormArray.removeAt method');
    }
    super.removeAt(index);
    const length = this.controls.length;
    this._controlRemovedFn(index);
    if (length === this.controls.length) {
      super.removeAt(index);
    } else {
      this.updateValueAndValidity({ emitEvent: opts?.emitEvent });
    }
  }

  public setEnable(enable = true, opts?: ControlEventOptions) {