requiredValidator<TEntity> function

ValidatorsFunction<FormControl<TEntity>> requiredValidator<TEntity>({
  1. String message = 'Поле обязательно',
  2. dynamic eventType = ValidationEventTypes.Error,
})

Implementation

ValidatorsFunction<FormControl<TEntity>> requiredValidator<TEntity>(
        {String message = 'Поле обязательно',
        eventType = ValidationEventTypes.Error}) =>
    (FormControl<TEntity> control) async {
      if (control.value == null ||
          (TEntity == String && (control.value as String).isEmpty == true)) {
        return [
          ValidationEvent(
            key: requiredValidatorKey,
            message: message,
            type: eventType,
          )
        ];
      }
      return [];
    };