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: Validation should ignore when a field is empty and is not required #188

Merged
merged 3 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ func TestRule_Bool(t *testing.T) {
assert.Nil(t, err, c.description)
assert.NotNil(t, validator, c.description)
assert.Equal(t, map[string]string{"bool": "name1 value must be a bool"}, validator.Errors().Get("name1"))
assert.Equal(t, map[string]string{"bool": "name2 value must be a bool"}, validator.Errors().Get("name2"))
assert.Nil(t, validator.Errors().Get("name2"))
assert.Equal(t, map[string]string{"bool": "name3 value must be a bool"}, validator.Errors().Get("name3"))
},
},
Expand Down Expand Up @@ -2064,9 +2064,12 @@ func TestRule_Date(t *testing.T) {
validator, err := validation.Make(map[string]any{
"name": "2022-12-25",
"name1": "2022/12/25",
"name2": "",
}, map[string]string{
"name": "required|date",
"name1": "required|date",
"name2": "date",
"name3": "date",
})
assert.Nil(t, err, c.description)
assert.NotNil(t, validator, c.description)
Expand Down
2 changes: 1 addition & 1 deletion validation/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func init() {
validate.Config(func(opt *validate.GlobalOption) {
opt.StopOnError = false
opt.SkipOnEmpty = false
opt.SkipOnEmpty = true
})
}

Expand Down