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

Exclude If doesn't work on boolean and nil parametr #1310

Closed
2 tasks done
DarkReduX opened this issue Aug 20, 2024 · 0 comments · Fixed by #1313
Closed
2 tasks done

Exclude If doesn't work on boolean and nil parametr #1310

DarkReduX opened this issue Aug 20, 2024 · 0 comments · Fixed by #1313

Comments

@DarkReduX
Copy link

DarkReduX commented Aug 20, 2024

  • I have looked at the documentation here first? Yes
  • I have looked at the examples provided that may showcase my question here? Yes in doc.go too

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

exclude_if doesn't work with 'nil','true','false' values in provided parametrs

Examples:

// exclude the field if the Field1 is equal to the parameter given:
Usage: excluded_if=Field1 foobar

// exclude the field if the Field1 and Field2 is equal to the value respectively:
Usage: excluded_if=Field1 foo Field2 bar

Code sample, to showcase or reproduce:

type Struct1 struct {
  Field1 bool
  Field2 *string `validate:"excluded_if=Field1 false"`
}

type Struct2 struct {
  Field1 bool
  Field2 *string `validate:"excluded_if=!Field1"`
}

func main() {
ctx := context.Background()

  vldtr := validator.New()
str := "321321"
vldtr.StructCtx(ctx,Struct1{false, str})

vldtr.StructCtx(ctx, Struct2{false, str})
}

// Output: !panic recovered: Bad field type *int64

Output

@DarkReduX DarkReduX changed the title e Exclude If doesn't work on boolean and nil parametr Aug 20, 2024
ganeshdipdumbare added a commit to ganeshdipdumbare/validator that referenced this issue Aug 27, 2024
- fixes go-playground#1310
- add check for pointers in case of excluded_if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant