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

Add isEmpty on required string #27

Open
morrowyn opened this issue May 18, 2021 · 2 comments
Open

Add isEmpty on required string #27

morrowyn opened this issue May 18, 2021 · 2 comments

Comments

@morrowyn
Copy link

ValidationBuilder().required("").build()
only works on strings that are null. However when a string is empty "" the validator says that it's valid. I expected an invalid error.

image

@TheJosh
Copy link

TheJosh commented May 24, 2021

Yeah, it appears that when using a TextEditingController, the value is often silently converted from a null into an empty string, so as a result this required check never hits, even though the fields are empty.

Workaround is adding minLength(1) but this is a bit silly and also gives a not very helpful error message.

@TheJosh
Copy link

TheJosh commented May 24, 2021

Another workaround is an extension method:

extension CustomValidationBuilder on ValidationBuilder {
  notEmpty() => add((value) {
    return value.isEmpty ? 'This field is required' : null;
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants