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

Validating a struct field which is a list #64

Open
jfrense opened this issue Jul 14, 2019 · 0 comments
Open

Validating a struct field which is a list #64

jfrense opened this issue Jul 14, 2019 · 0 comments

Comments

@jfrense
Copy link

jfrense commented Jul 14, 2019

I am having trouble using vex to validate a field in a struct that consists of a list of values.

For example If I have the following struct:

user = %{emails_list: ["[email protected]","incorrect@email"]}

and then I use vex.valid? to validate the emails:

 Vex.valid?(user,
    emails_list: [
      presence: [message: "can't be empty"],
      format: [
        with: ~r/\S+@\S+\.\S+/,
        allow_nil: false,
        allow_blank: false,
        string: true,
        message: "can't be empty"
      ]
    ]
  )

I am getting True back even though one of the emails in the list is invalid. To verify I tested it the values without the list and it is returning the correct validation result.

Is it possible to validate a struct with a list as one of its fields? Or do I have to write a validator with a custom function to map over each value in the list to validate it?

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

1 participant