View Source Torch.FilterView (Torch v4.1.0)

Provides input generators for Torch's filter sidebar.

Link to this section Summary

Functions

Generates a select box for a belongs_to association.

Generates a filter select box for a boolean field.

Generates a "before/after" filter type select box for a given date or datetime field.

Generates a filter input for a number field.

Generates a "contains/equals" filter type select box for a given string or text field.

Generates a filter input for a string field.

DEPRECATED: Generates a filter input for a text field. Use the filter_string_input/3 function instead.

Generates a number filter type select box for a given number field.

Link to this section Types

Specs

field() :: atom() | String.t()

Specs

input_type() :: atom() | String.t()

Specs

prefix() :: atom() | String.t()

Link to this section Functions

Link to this function

filter_assoc_select(prefix, field, options, params)

View Source

Specs

filter_assoc_select(prefix(), field(), list(), map()) :: Phoenix.HTML.safe()

Generates a select box for a belongs_to association.

Example

iex> params = %{"post" => %{"category_id_equals" => 1}}
...> filter_assoc_select(:post, :category_id, [{"Articles", 1}], params) |> safe_to_string()
"<select id=\"post_category_id_equals\" name=\"post[category_id_equals]\"><option value=\"\">Choose one</option><option selected value=\"1\">Articles</option></select>"
Link to this function

filter_boolean_input(prefix, field, params)

View Source

Specs

filter_boolean_input(prefix(), field(), map()) :: Phoenix.HTML.safe()

Generates a filter select box for a boolean field.

Example

iex> params = %{"post" => %{"draft_equals" => "false"}}
iex> filter_boolean_input(:post, :draft, params) |> safe_to_string()
"<select class=\"boolean-type\" id=\"post_draft_equals\" name=\"post[draft_equals]\"><option value=\"any\"></option><option value=\"true\">True</option><option selected value=\"false\">False</option></select>"
Link to this function

filter_date_input(prefix, field, params, input_type \\ :range)

View Source

Specs

filter_date_input(prefix(), field(), map(), input_type()) :: Phoenix.HTML.safe()

Generates a filter datepicker input.

Example

iex> params = %{"post" => %{"inserted_at_between" => %{"start" => "01/01/2018", "end" => "01/31/2018"}}}
...> filter_date_input(:post, :inserted_at, params) |> safe_to_string()
"<input class=\"datepicker start\" name=\"post[inserted_at_between][start]\" placeholder=\"Select Start Date\" type=\"text\" value=\"01/01/2018\"><input class=\"datepicker end\" name=\"post[inserted_at_between][end]\" placeholder=\"Select End Date\" type=\"text\" value=\"01/31/2018\">"

iex> params = %{"post" => %{"inserted_at_between" => %{"start" => "01/01/2018", "end" => "01/31/2018"}}}
...> filter_date_input(:post, :inserted_at, params, :range) |> safe_to_string()
"<input class=\"datepicker start\" name=\"post[inserted_at_between][start]\" placeholder=\"Select Start Date\" type=\"text\" value=\"01/01/2018\"><input class=\"datepicker end\" name=\"post[inserted_at_between][end]\" placeholder=\"Select End Date\" type=\"text\" value=\"01/31/2018\">"

iex> params = %{"post" => %{"inserted_at_before" => "01/01/2018"}}
...> filter_date_input(:post, :inserted_at, params, :select) |> safe_to_string()
"<input class=\"datepicker\" name=\"post[inserted_at_before]\" placeholder=\"Select Date\" type=\"text\" value=\"01/01/2018\">"

iex> params = %{"post" => %{"inserted_at_after" => "01/01/2018"}}
...> filter_date_input(:post, :inserted_at, params, :select) |> safe_to_string()
"<input class=\"datepicker\" name=\"post[inserted_at_after]\" placeholder=\"Select Date\" type=\"text\" value=\"01/01/2018\">"
Link to this function

filter_date_select(prefix, field, params)

View Source

Specs

filter_date_select(prefix(), field(), map()) :: Phoenix.HTML.safe()

Generates a "before/after" filter type select box for a given date or datetime field.

Example

iex> params = %{"post" => %{"updated_at_after" => "01/01/2019"}}
...> filter_date_select(:post, :updated_at, params) |> safe_to_string()
"<select class=\"filter-type\" id=\"filters_\" name=\"filters[]\"><option value=\"post[updated_at_before]\">Before</option><option selected value=\"post[updated_at_after]\">After</option></select>"
Link to this function

filter_number_input(prefix, field, params)

View Source

Specs

filter_number_input(prefix(), field(), map()) :: Phoenix.HTML.safe()

Generates a filter input for a number field.

Example

iex> params = %{"post" => %{"rating_equals" => 5}}
...> filter_number_input(:post, :rating, params) |> safe_to_string()
"<input id=\"post_rating_equals\" name=\"post[rating_equals]\" type=\"number\" value=\"5\">"
Link to this function

filter_select(prefix, field, params)

View Source

Specs

filter_select(prefix(), field(), map()) :: Phoenix.HTML.safe()

Generates a "contains/equals" filter type select box for a given string or text field.

Example

iex> params = %{"post" => %{"title_contains" => "test"}}
...> filter_select(:post, :title, params) |> safe_to_string()
"<select class=\"filter-type\" id=\"filters_\" name=\"filters[]\"><option selected value=\"post[title_contains]\">Contains</option><option value=\"post[title_equals]\">Equals</option></select>"
Link to this function

filter_string_input(prefix, field, params)

View Source

Specs

filter_string_input(prefix(), field(), map()) :: Phoenix.HTML.safe()

Generates a filter input for a string field.

Example

iex> params = %{"post" => %{"title_contains" => "test"}}
iex> filter_string_input(:post, :title, params) |> safe_to_string()
"<input id=\"post_title_contains\" name=\"post[title_contains]\" type=\"text\" value=\"test\">"
Link to this function

filter_text_input(prefix, field, params)

View Source
This function is deprecated. Use filter_string_input/3 instead.

DEPRECATED: Generates a filter input for a text field. Use the filter_string_input/3 function instead.

Link to this function

number_filter_select(prefix, field, params)

View Source

Specs

number_filter_select(prefix(), field(), map()) :: Phoenix.HTML.safe()

Generates a number filter type select box for a given number field.

Example

iex> params = %{"post" => %{"rating_greater_than" => 0}}
...> number_filter_select(:post, :rating, params) |> safe_to_string()
"<select class=\"filter-type\" id=\"filters_\" name=\"filters[]\"><option value=\"post[rating_equals]\">Equals</option><option selected value=\"post[rating_greater_than]\">Greater Than</option><option value=\"post[rating_greater_than_or]\">Greater Than Or Equal</option><option value=\"post[rating_less_than]\">Less Than</option></select>"