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 boolean field with false #184

Open
moyuanhuang opened this issue Apr 30, 2023 · 2 comments
Open

Validate required boolean field with false #184

moyuanhuang opened this issue Apr 30, 2023 · 2 comments

Comments

@moyuanhuang
Copy link

Hi, I noticed that when using the Required validator against a boolean field with value equals false, the validator will raise

FIELD_NAME: cannot be blank.

Is this expected?

Sample code: https://go.dev/play/p/SkiEIx2aaQN

@rngallen
Copy link

rngallen commented May 4, 2023

Yes as per source code

Required is a validation rule that checks if a value is not empty.
A value is considered not empty if

  • integer, float: not zero
  • bool: true
  • string, array, slice, map: len() > 0
  • interface, pointer: not nil and the referenced value is not empty
  • any other types

@slessard
Copy link

See this pull request in jellydator-validation that makes clear the behavior for booleans with the Required rule.

jellydator#18

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

3 participants