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

Validation errors for nested structs #39

Open
chrisjowen opened this issue Nov 15, 2016 · 3 comments
Open

Validation errors for nested structs #39

chrisjowen opened this issue Nov 15, 2016 · 3 comments

Comments

@chrisjowen
Copy link

Hey, nice library. Im wondering if its possible to expose the errors for nested structs currently I am using the Vex.Struct module and defining a custom function for validating a nested structure i.e.

validates :nested, &NestedVexStruct.valid?/1

This works great and gives me the ability to run the nested validations but if it fails the error I get is only associated with this top level validator and not the actual causes in the sub validator. Any ideas around this?

@dwhelan
Copy link

dwhelan commented Dec 20, 2017

@chrisjowen were you able to resolve this?

@dkushner
Copy link

dkushner commented Oct 7, 2018

@dwhelan I'm ssuming that since this issue is about two years old, I don't have much hope of a resolution in this case, huh?

@larskluge
Copy link

larskluge commented Apr 9, 2020

I realize that since this question has been asked hoverboards have been invented.. however, the following seems to work well for me (so far):

validates :nested, &Vex.validate/1

.validate instead of .valid? to propagate the error message. This works for me since my nested struct implements use Vex.Struct. Otherwise I noticed nested fields are somewhat supported:

assert nested_errors == Vex.errors(%NestedTestRecord{author: [name: ""]})

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

No branches or pull requests

4 participants