FormGroup constructor
- Map<
String, AbstractControl> controls, { - List<
ValidatorFunction> validators = const [], - List<
AsyncValidatorFunction> asyncValidators = const [], - int asyncValidatorsDebounceTime = 250,
- bool disabled = false,
Creates a new FormGroup instance.
When instantiating a FormGroup, pass in a Map of child controls as the first argument.
The key for each child registers the name for the control.
Example:
final form = FromGroup({
'name': FormControl(defaultValue: 'John Doe'),
'email': FormControl(),
});
The group can optionally have validators
that validates
the group each time the value changes.
The group can optionally have asyncValidators
that validates
asynchronously the group 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 groups are
disabled by default.
See also AbstractControl.validators
Implementation
FormGroup(
Map<String, AbstractControl<dynamic>> controls, {
List<ValidatorFunction> validators = const [],
List<AsyncValidatorFunction> asyncValidators = const [],
int asyncValidatorsDebounceTime = 250,
bool disabled = false,
}) : assert(
!controls.keys.any((name) => name.contains(_controlNameDelimiter)),
'Control name should not contain dot($_controlNameDelimiter)'),
super(
validators: validators,
asyncValidators: asyncValidators,
asyncValidatorsDebounceTime: asyncValidatorsDebounceTime,
disabled: disabled,
) {
addAll(controls);
if (disabled) {
markAsDisabled(emitEvent: false);
}
}