View Source Backpex.Filters.Select behaviour (Backpex v0.8.2)

Tbe select filter renders a select box for the implemented options/0 and prompt/0 callbacks. The prompt/0 callback defines the key for the nil value added as first option.

See the following example for an implementation of an event status filter.

defmodule MyAppWeb.Filters.EventStatusSelect do
  use Backpex.Filters.Select

  @impl Backpex.Filter
  def label, do: "Event status"

  @impl Backpex.Filters.Select
  def prompt, do: "Select an option..."

  @impl Backpex.Filters.Select
  def options, do: [
    {"Open", :open},
    {"Close", :close},
  ]

  @impl Backpex.Filter
  def query(query, attribute, value) do
      where(query, [x], field(x, ^attribute) == ^value)
  end
end

use Backpex.Filters.Select

When you use Backpex.Filters.Select, the Backpex.Filters.Select module will set @behavior Backpex.Filters.Select. In addition it will add a render and render_form function in order to display the corresponding filter.

Summary

Callbacks

The list of options for the select filter.

The select's default option.

Functions

Attributes

  • value (:any) (required)
  • options (:list) (required)

Attributes

  • form (:any) (required)
  • field (:atom) (required)
  • value (:any) (required)
  • options (:list) (required)
  • prompt (:string) (required)

Callbacks

@callback options() :: [{String.t() | atom(), String.t() | atom()}]

The list of options for the select filter.

@callback prompt() :: String.t() | atom()

The select's default option.

Functions

Link to this function

option_value_to_label(options, value)

View Source
Link to this function

query(query, attribute, value)

View Source

Attributes

  • value (:any) (required)
  • options (:list) (required)

Attributes

  • form (:any) (required)
  • field (:atom) (required)
  • value (:any) (required)
  • options (:list) (required)
  • prompt (:string) (required)