FormArray<T> constructor

FormArray<T>(
  1. List<AbstractControl<T>> controls, {
  2. List<ValidatorFunction> validators = const [],
  3. List<AsyncValidatorFunction> asyncValidators = const [],
  4. int asyncValidatorsDebounceTime = 250,
  5. bool disabled = false,
})

Creates a new FormArray instance.

When instantiating a FormGroup, pass in a collection of child controls as the first argument.

Example:

final form = FromGroup({
  'name': FormControl(defaultValue: 'John Doe'),
  'aliases': FormArray([
    FormControl(defaultValue: 'john'),
    FormControl(defaultValue: 'little john'),
  ]),
});

The array can optionally have validators that validates the array each time the value changes.

The array can optionally have asyncValidators that validates asynchronously the array each time the value changes. Asynchronous validation executes after the synchronous validation, and is performed only if the synchronous validation is successful. This check allows forms to avoid potentially expensive async validation processes (such as an HTTP request) if the more basic validation methods have already found invalid input.

You can set an asyncValidatorsDebounceTime in millisecond to set a delay time before trigger async validators. This is useful for minimizing request to a server. The default value is 250 milliseconds.

If disabled is true then all children controls of the array are disabled by default.

See also AbstractControl.validators

Implementation

FormArray(
  List<AbstractControl<T>> controls, {
  List<ValidatorFunction> validators = const [],
  List<AsyncValidatorFunction> asyncValidators = const [],
  int asyncValidatorsDebounceTime = 250,
  bool disabled = false,
}) : super(
        validators: validators,
        asyncValidators: asyncValidators,
        asyncValidatorsDebounceTime: asyncValidatorsDebounceTime,
        disabled: disabled,
      ) {
  addAll(controls);

  if (disabled) {
    markAsDisabled(emitEvent: false);
  }
}