resetState method

void resetState(
  1. List<ControlState<T>> state
)

Resets the array, marking all controls as untouched, and setting a state for children with an initial value and disabled state.

The state is a collection of states for children that resets each control with an initial value and disabled state.

Reset the values in a form array and the disabled status for the

first control

final array = FormArray<String>([
  FormControl<String>(),
  FormControl<String>(),
]);

array.resetState([
  ControlState(value: 'name', disabled: true),
  ControlState(value: 'last'),
]);

console.log(array.value);  // output: ['name', 'last name']
console.log(array.control('0').disabled);  // output: true

```

Implementation

void resetState(List<ControlState<T>> state) {
  if (state.isEmpty) {
    reset();
  } else {
    for (var i = 0; i < _controls.length; i++) {
      _controls[i].reset(
        value: i < state.length ? state.elementAt(i).value : null,
        disabled: i < state.length ? state.elementAt(i).disabled : null,
        updateParent: false,
      );
    }

    updatePristine();
    updateValueAndValidity();
  }
}