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

excluded_with doesn't work with structures #906

Open
2 tasks done
petitout opened this issue Feb 28, 2022 · 4 comments
Open
2 tasks done

excluded_with doesn't work with structures #906

petitout opened this issue Feb 28, 2022 · 4 comments

Comments

@petitout
Copy link

petitout commented Feb 28, 2022

  • I have looked at the documentation here first?
  • I have looked at the examples provided that may showcase my question here?

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

excluded_with doesn't work with structures

Code sample, to showcase or reproduce:

type Test2 struct {
	Test2 string
}

type Test struct {
	Fire  *Test2 `validate:"excluded_with=Water"`
	Water *Test2 `validate:"excluded_with=Fire"`
}

func main() {
	data := &Test2{}
	v := validator.New()
	fmt.Println(v.Struct(&Test{Fire: data, Water: data})) 
}

google playground : https://go.dev/play/p/krYBBvE4zWZ

@petitout petitout changed the title exclude_with doesn't work with structures excluded_with doesn't work with structures Feb 28, 2022
@kaifresh
Copy link

Also v curious if there's an answer to this one. @deankarn could you shed any light?

@kevbook
Copy link

kevbook commented Nov 28, 2022

This seems like a bug, I've tested this one too

@StrangeYear
Copy link

Is there any change in this question

@mxmaxime
Copy link

Same here, and I didn't find any workaround :/

deankarn pushed a commit that referenced this issue Aug 6, 2023
## Fixes #367, #906

**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular
change.

A test has been added for custom tags, however I was not brave enough to
actually update the tests for all required/excluded tag variants before
getting an initial feedback, but I'm willing to do so if this ever gets
any further.

Same goes for documentation.

The implementation supports both struct and struct pointer validations
for custom tags and all required/excluded tag variants.

Struct validity is evaluated first and fields are evaluated only if the
struct is valid, though I'm not sure if this is the desired behavior.

@go-playground/validator-maintainers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants