ozzo-validation
ozzo-validation copied to clipboard
Validate required boolean field with `false`
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
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
See this pull request in jellydator-validation that makes clear the behavior for booleans with the Required
rule.
https://github.com/jellydator/validation/pull/18