Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate purity from validity #45

Closed
definitelyokay opened this issue Oct 26, 2021 · 0 comments · Fixed by #48
Closed

Separate purity from validity #45

definitelyokay opened this issue Oct 26, 2021 · 0 comments · Fixed by #48
Assignees
Labels
feature A new feature or request

Comments

@definitelyokay
Copy link

Formz currently (and incorrectly) conflates purity with validity.

Imagine a class which contains a username input field (which is un remarkable implementation of a FormzInput).

class RegistrationState {
  final UsernameInput username;
  bool get isBusy => ...
  bool get canSubmit =>
      Formz.validate([username]) == FormzStatus.valid && !isBusy;
}

Currently, the following test fails, despite the fact that unicorn is considered a valid string by the implementation of UsernameInput (not shown).

test('true when username is valid and not busy', () {
  const state = RegistrationState(
    username: UsernameInput.pure(value: 'unicorn'),
    isCheckingUsername: false,
    status: RegistrationStatus.editing,
  );
  expect(state.canSubmit, true);
});

The reason for the failure is because the value of Formz.validate([username]) is FormzStatus.pure, rather than FormzStatus.valid.

I believe FormzInput shoulds have a separate field which tracks the field's purity. Additionally, it may be suitable to have a displayError property which is null when the field is pure, as UI's commonly disregard errors on unmodified (but incorrect) fields.

abstract class FormzInput<T, E> {
  final E? get displayError => pure ? null : error;
  ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants