formz icon indicating copy to clipboard operation
formz copied to clipboard

Some fields do not require validation

Open andrefedev opened this issue 1 year ago • 2 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;
}

andrefedev avatar Mar 16 '23 22:03 andrefedev

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.

adityandar avatar Jul 29 '23 13:07 adityandar

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

codakkk avatar Oct 07 '23 09:10 codakkk