VeryGoodOpenSource / formz

A unified form representation in Dart used at Very Good Ventures 🦄

Home Page:https://pub.dev/packages/formz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some fields do not require validation

andrefedev opened this issue · comments

Every time a FormZInput is defined we must add a validation error even if we never get to use it. Some fields do not require validation, but do require being inside the form to later verify if the field has changed its value.

Example:

// abstract class FormzInput<T, E>

enum StatusMemberInputError { none }

class StatusMemberInput extends FormzInput<bool, StatusMemberInputError> {
  const StatusMemberInput.pure({bool value = false}) : super.pure(value);

  const StatusMemberInput.dirty({bool value = false}) : super.dirty(value);

  @override
  StatusMemberInputError? validator(bool value) => null;
}

have similar use case, currently using your example, but I don't think it's the good way because we still create the error enum.

I wrote a wrapper for this case:

class UnirequiredInput<T> extends FormzInput<T?, void> {
  const UnirequiredInput.pure() : super.pure(null);
  const UnirequiredInput.dirty({T? value}) : super.dirty(value);

  @override
  void validator(T? value) {}
}

But this is just a workaround