go-ozzo / ozzo-validation

An idiomatic Go (golang) validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags.
MIT License
3.73k stars 224 forks source link

Validate required boolean field with `false` #184

Open moyuanhuang opened 1 year ago

moyuanhuang commented 1 year ago

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 commented 1 year ago

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

slessard commented 1 year ago

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