Talos v1.6.2 Talos.Types.MapType View Source

MapType for validation maps

Fields are tuples {key, type, options \ []}:

key - string or atom, key of map

type - Talos defined Type

options:

* `optional`: true/false, if false - there will be error on key missing

For example:


  iex> import Talos
  iex> Talos.valid?(map(), %{foo: :bar})
  true
  iex> user_params = map(fields: [
  ...>  field(key: "email", type: string(min_length: 5, max_length: 255, regexp: ~r/.*@.*/)),
  ...>  field(key: "age", type: integer(gteq: 18, allow_nil: true)),
  ...>  field(key: "interests", type: list(type: string()), optional: true)
  ...> ])
  iex> Talos.valid?(user_params, %{})
  false
  iex> Talos.valid?(user_params, %{"email" => "bob@gmail.com", "age" => 30})
  true
  iex> Talos.valid?(user_params, %{"email" => "bob@gmail.com", "age" => 30, interests: ["elixir"]})
  true

Link to this section Summary

Functions

Callback implementation for Talos.Types.errors/2.

Callback implementation for Talos.Types.valid?/2.

Link to this section Types

Link to this type

t()

View Source
t() :: %atom(){
  allow_nil: boolean(),
  allow_blank: boolean(),
  fields: [Talos.Types.MapType.Field.t()] | nil
}

Link to this section Functions

Callback implementation for Talos.Types.errors/2.

Callback implementation for Talos.Types.valid?/2.