Skip to content

Some fields do not require validation #86

Description

@andrefedev

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;
}

Activity

  1. adityandar commented on Jul 29, 2023

    @adityandar

    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.

  2. codakkk commented on Oct 7, 2023

    @codakkk

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions