ozzo-validation icon indicating copy to clipboard operation
ozzo-validation copied to clipboard

Validate required boolean field with `false`

Open moyuanhuang opened this issue 1 year ago • 2 comments

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

moyuanhuang avatar Apr 30 '23 18:04 moyuanhuang

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

rngallen avatar May 04 '23 15:05 rngallen

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

slessard avatar Sep 19 '23 18:09 slessard