Formex v0.6.7 Formex.Validator behaviour

Validator behaviour.

In Formex you can use any validation library. Of course, if proper adapter is already implemented.

Available adapters:

Installation

Setting default validator:

config/config.exs

config :formex,
  validator: Formex.Validator.Vex

Using another validator in a specific form type

def build_form(form) do
  form
  |> add(:name, :text_input)
  # ...
end

def validator, do: Formex.Validator.Vex

If you want to translate errors messages, set a translation function in config:

config :formex,
  translate_error: &AppWeb.ErrorHelpers.translate_error/1

or, if you can’t use function capture in config (for example with Distillery, issue #12), set this option in every form type:

def build_form(form) do
  form
  |> add(:name, :text_input)
  # ...
end

def translate_error, do: &AppWeb.ErrorHelpers.translate_error/1

The &AppWeb.ErrorHelpers.translate_error/1 is a function generated by Phoenix in /lib/app_web/views/error_helpers.ex. You can also set your own similar function.

Implementing adapter for another library

See implementation for Vex for example.

Summary

Functions

validate(form)

Callbacks

validate(form)
validate(form :: Formex.Form.t) :: List.t