setValidators method

void setValidators(
  1. List<ValidatorFunction> validators, {
  2. bool autoValidate = false,
  3. bool updateParent = true,
  4. bool emitEvent = true,
})

Sets the synchronous validators that are active on this control. Calling this overwrites any existing sync validators.

If autoValidate is true then the status of the control is recalculated after setting the new validators. If autoValidate is false (default) you must call updateValueAndValidity(), or assign a new value to the control for the new validation to take effect.

When updateParent is true or not supplied (the default) each change affects this control and its parent, otherwise only affects to this control. This argument is only taking into account if autoValidate is equals to true.

When emitEvent is true or not supplied (the default), both the statusChanges and valueChanges emit events with the latest status and value when the control is reset. When false, no events are emitted. This argument is only taking into account if autoValidate is equals to true.

Implementation

void setValidators(
  List<ValidatorFunction> validators, {
  bool autoValidate = false,
  bool updateParent = true,
  bool emitEvent = true,
}) {
  clearValidators();
  _validators.addAll(validators);

  if (autoValidate) {
    updateValueAndValidity(updateParent: updateParent, emitEvent: emitEvent);
  }
}