Skip to content

Validating a struct field which is a list #64

@jfrense

Description

@jfrense

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: ["correct@email.com","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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions