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

Fix boolean support for required_if, required_unless and eqfield #754

Merged
merged 2 commits into from
May 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix boolean support in requireCheckFieldValue, isEqField and isNeField
  • Loading branch information
Zane DeGraffenried committed Apr 16, 2021
commit 08356f8539dca47f241b5efdb0d1206bfab80014
12 changes: 12 additions & 0 deletions baked_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,9 @@ func isNeCrossStructField(fl FieldLevel) bool {
case reflect.Slice, reflect.Map, reflect.Array:
return int64(topField.Len()) != int64(field.Len())

case reflect.Bool:
return topField.Bool() != field.Bool()

case reflect.Struct:

fieldType := field.Type()
Expand Down Expand Up @@ -1085,6 +1088,9 @@ func isEqCrossStructField(fl FieldLevel) bool {
case reflect.Slice, reflect.Map, reflect.Array:
return int64(topField.Len()) == int64(field.Len())

case reflect.Bool:
return topField.Bool() == field.Bool()

case reflect.Struct:

fieldType := field.Type()
Expand Down Expand Up @@ -1132,6 +1138,9 @@ func isEqField(fl FieldLevel) bool {
case reflect.Slice, reflect.Map, reflect.Array:
return int64(field.Len()) == int64(currentField.Len())

case reflect.Bool:
return field.Bool() == currentField.Bool()

case reflect.Struct:

fieldType := field.Type()
Expand Down Expand Up @@ -1446,6 +1455,9 @@ func requireCheckFieldValue(fl FieldLevel, param string, value string, defaultNo

case reflect.Slice, reflect.Map, reflect.Array:
return int64(field.Len()) == asInt(value)

case reflect.Bool:
return field.Bool() == asBool(value)
}

// default reflect.String:
Expand Down