Formex v0.6.0 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: &App.ErrorHelpers.translate_error/1

The &App.ErrorHelpers.translate_error/1 is a function generated by Phoenix in /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