Validate tag omitempty, only base on field value

pull/657/head
nigelis 4 years ago
parent ea924ce89a
commit 6f81b7d8d0
  1. 2
      validator.go
  2. 10
      validator_test.go

@ -249,7 +249,7 @@ OUTER:
v.cf = cf
v.ct = ct
if !v.fldIsPointer && !hasValue(v) {
if !hasValue(v) {
return
}

@ -8858,6 +8858,16 @@ func TestRequiredWithout(t *testing.T) {
AssertError(t, errs, "Field6", "Field6", "Field6", "Field6", "required_without")
AssertError(t, errs, "Field7", "Field7", "Field7", "Field7", "required_without")
AssertError(t, errs, "Field8", "Field8", "Field8", "Field8", "required_without")
test3 := struct {
Field1 *string `validate:"required_without=Field2,omitempty,min=1" json:"field_1"`
Field2 *string `validate:"required_without=Field1,omitempty,min=1" json:"field_2"`
}{
Field1: &fieldVal,
}
errs = validate.Struct(&test3)
Equal(t, errs, nil)
}
func TestRequiredWithoutAll(t *testing.T) {

Loading…
Cancel
Save