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

validate_required returns true when key exists but is empty #237

Open
acoustep opened this issue Nov 29, 2019 · 1 comment
Open

validate_required returns true when key exists but is empty #237

acoustep opened this issue Nov 29, 2019 · 1 comment

Comments

@acoustep
Copy link

I wanted to check if this is intended or not. I'm happy to try and put together a pull request if you'd like this implemented.

At the moment validate_required returns true so long as the field exists in the changeset. This differs from Elixir Ecto's implementation which from their docs says:

If the value of a field is nil or a string made only of whitespace, the changeset is marked as invalid, the field is removed from the changeset's changes, and an error is added. An error won't be added if the field already has an error.

Should Crecto follow the same process - as well as including an additional parameter for an option to trim whitespace? e.g.

validate_required :name, {trim: true}
@fridgerator
Copy link
Member

@acoustep Yes this sounds good to me!

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