Library that integrates Vex validator with Formex.
def deps do
[{:formex_vex, "~> 0.1.0"}]
end
config/config.exs
config :formex,
validator: Formex.Validator.Vex
See Formex.Validator docs for more info
def build_form(form) do
form
|> add(:name, :text_input, validation: [presence: :true, length: [in: 10..150]])
|> add(:content, :textarea, validation: [presence: [message: "can't be blank"]])
|> add(:slug, :text_input, validation: fn (text) ->
if !Repo.get_by(Article, slug: text) do
:ok
else
{:error, "already used!!1"}
end
end)
# ...
end
See Vex documentation for more options