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

"sometimes" validator #19

Open
ozziexsh opened this issue Apr 7, 2023 · 0 comments
Open

"sometimes" validator #19

ozziexsh opened this issue Apr 7, 2023 · 0 comments

Comments

@ozziexsh
Copy link
Owner

ozziexsh commented Apr 7, 2023

validator that only proceeds if the data key exists, only useful for maps

ie

input = %{
  name: "joe"
}

rules = %{
  name: [type: :string],
  age: [sometimes: true, min: 18]
}

# passes because age isn't present in input, so no validations are ran for age
{:ok, data} = Validate.validate(input, rules)

input = %{
  name: "joe",
  age: 15
}

# now the `min` validator runs because age is present in the input
{:error, errors} = Validate.validate(input, rules)
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