View Source ExTeal.Fields.BooleanGroup (ExTeal v0.27.0)

A group of boolean inputs that represent a map, or embedded schema where each value is a boolean. Useful for embedding features, permissions, or roles into a schema.

If the field represents and embedded schema as an embeds_one, the field will set a default set of options based on the fields of the embedded schema. It assumes that every field in the embed is a boolean:

defmodule Permissions do
  use Ecto.Schema

  embedded_schema do
    field :read, :boolean, default: false
    field :write, :boolean, default: false
    field :delete, :boolean, default: false
  end

  def changeset(permissions, attrs) do
    cast(permission, attrs, [:read, :write, :delete])
  end
end

defmodule Post do
  use Ecto.Schema

  schema "posts" do
    field :title, :string
    embeds_one :permissions, Permissions
  end
end


def PostResource do
  use ExTeal.Resource
  def model, do: Post

  def fields, do: [
    Text.make(:title),
    BooleanGroup.make(:permissions)
  ]
end

You can also define a boolean group over a plain map type and manually define the options as a map of keys and labels:

defmodule Post do
  use Ecto.Schema

  schema "posts" do
    field :title, :string
    field :permissions, :map
  end
end

def PostResource do
  use ExTeal.Resource
  def model, do: Post

  def fields, do: [
    Text.make(:title),
    BooleanGroup.make(:permissions)
    |> BooleanGroup.options(%{
      "read" => "Read",
      "write" => "Write"
    })
  ]
end

The options function can also be used to override the default options when used with an embedded schema if the options need to be translated into human readable values.

Summary

Functions

Callback implementation for ExTeal.Field.filterable_as/0.

Callback implementation for ExTeal.Field.make/2.

Customize the text displayed in the event that a field contains no values.

Add the available options to manage in the boolean group

Functions

Callback implementation for ExTeal.Field.filterable_as/0.

Link to this function

make(name, label \\ nil)

View Source

Callback implementation for ExTeal.Field.make/2.

Link to this function

no_value_text(field, text)

View Source
@spec no_value_text(ExTeal.Field.t(), String.t()) :: ExTeal.Field.t()

Customize the text displayed in the event that a field contains no values.

@spec options(ExTeal.Field.t(), any()) :: ExTeal.Field.t()

Add the available options to manage in the boolean group

Link to this function

value_for(field, model, method)

View Source

Callback implementation for ExTeal.Field.value_for/3.