maxValueValidator<TEntity extends num> function

ValidatorsFunction<FormControl<TEntity>> maxValueValidator<TEntity extends num>({
  1. TEntity? max,
  2. TEntity getterMax()?,
  3. String message = 'Значение слишком большое',
  4. dynamic eventType = ValidationEventTypes.Error,
})

Implementation

ValidatorsFunction<FormControl<TEntity>>
    maxValueValidator<TEntity extends num>({
  TEntity? max,
  TEntity Function()? getterMax,
  String message = 'Значение слишком большое',
  eventType = ValidationEventTypes.Error,
}) {
  assert(
      !(max != null && getterMax != null), "use \"value\" or \"getterValue\"");
  assert(
      !(max == null && getterMax == null), "use \"value\" or \"getterValue\"");
  final getMax = getterMax ?? () => max!;
  return (FormControl<TEntity> control) async {
    if (control.value == null) {
      return [];
    }
    final maxValue = getMax();
    final value = control.value;
    // if (typeof value === 'string') {
    //   if (typeof maxValue === 'number') {
    //     value = +value;
    //   } else if (maxValue instanceof Date) {
    //     value = new Date(value);
    //   }
    // }
    if (maxValue < value) {
      return [
        ValidationEvent(
          key: maxValueValidatorKey,
          message: message,
          type: eventType,
        )
      ];
    }
    return [];
  };
}