Backpex.HTML.Form (Backpex v0.23.0)

Copy Markdown View Source

Contains all Backpex form components.

Summary

Components

Generates a generic error message.

Displays a help text.

Renders the form of an inline edit on the index view.

Renders an input.

Renders a searchable multi select.

Components

error(assigns)

Generates a generic error message.

Attributes

  • class (:string) - Defaults to nil.

Slots

  • inner_block (required)

help_text(assigns)

Displays a help text.

Attributes

  • id (:string) - Defaults to nil.
  • class (:string) - Defaults to nil.

Slots

  • inner_block (required)

index_form(assigns)

Renders the form of an inline edit on the index view.

The index view saves the value of the form with all of its assigns if the field implements Backpex.Field.index_editable_change/3. Assign the form with Backpex.Field.assign_index_form/1 and render its input for @form[:value] inside.

The form sends an "index-edit" event to the LiveView. LiveView does not recover it after a reconnect, as that would save the value of every index form again.

Attributes

  • form (:any) (required) - form assigned by Backpex.Field.assign_index_form/1.
  • name (:atom) (required) - name / key of the item field.
  • item (:map) (required) - the item that is edited.
  • live_resource (:atom) (required) - module of the live resource.
  • Global attributes are accepted.

Slots

  • inner_block (required)

input(assigns)

Renders an input.

Attributes

  • id (:any) - Defaults to nil.
  • name (:any)
  • label (:string) - Defaults to nil.
  • help_text (:string) - Defaults to nil.
  • value (:any)
  • type (:string) - Defaults to "text". Must be one of "checkbox", "checkgroup", "color", "date", "datetime-local", "email", "file", "hidden", "month", "number", "password", "range", "radio", "search", "select", "tel", "text", "textarea", "time", "toggle", "url", or "week".
  • field (Phoenix.HTML.FormField) - a form field struct retrieved from the form, for example: @form[:email].
  • errors (:list) - Defaults to [].
  • checked (:boolean) - the checked flag for checkbox inputs.
  • prompt (:string) - the prompt for select inputs. Defaults to nil.
  • options (:list) - the options to pass to Phoenix.HTML.Form.options_for_select/2.
  • multiple (:boolean) - the multiple flag for select inputs. Defaults to false.
  • class (:any) - additional classes for the container element. Defaults to nil.
  • input_class (:any) - the input class to use over defaults. Defaults to nil.
  • error_class (:any) - the input error class to use over defaults. Defaults to nil.
  • translate_error_fun (:any) - a custom function to map form errors. Defaults to &Function.identity/1.
  • hide_errors (:boolean) - if errors should be hidden. Defaults to false.
  • Global attributes are accepted. Supports all globals plus: ["accept", "autocomplete", "capture", "cols", "disabled", "form", "list", "max", "maxlength", "min", "minlength", "multiple", "pattern", "placeholder", "readonly", "required", "rows", "size", "step", "aria-*"].

Slots

  • inner_block

multi_select(assigns)

Renders a searchable multi select.

Selected values whose options are not in options (e.g. because they are hidden by the search) are rendered as hidden inputs, so they are still submitted with the form. Callers must not render their own inputs for them.

Attributes

  • prompt (:string) (required) - string that will be shown when no option is selected.
  • readonly (:boolean) - whether the dropdown is readonly. Defaults to false.
  • help_text (:string) - help text to be displayed below input. Defaults to nil.
  • not_found_text (:string) (required) - string that will be shown when there are no options.
  • options (:list) (required) - a list of options for the select.
  • search_input (:string) (required) - to prefill and or persist the search term for rerendering.
  • event_target (:any) (required) - the target that handles the events of this component.
  • field_options (:map) (required) - field options for the corresponding field.
  • field (:any) (required) - form field the select should be for.
  • selected (:list) (required) - the selected values.
  • show_select_all (:boolean) (required) - whether to display the select all button.
  • show_more (:boolean) (required) - whether there are more options to show.
  • search_event (:string) - the event that will be sent when the search input changes. Defaults to "search".
  • hide_search (:boolean) - if search should be hidden. Defaults to false.
  • hide_errors (:boolean) - if errors should be hidden. Defaults to false.
  • live_resource (:atom) - the live resource module. Defaults to nil.
  • aria_labelledby (:string) - accessible labelledby for screen readers added to the trigger element.

Functions

currency_input(assigns)

Renders a masked input for currencies.

A Phoenix.HTML.FormField may be passed as argument, which is used to retrieve the input name, id, and values. Otherwise all attributes may be passed explicitly.

Examples

<.currency_input field={@form[:amount]} unit="€" unit_position={:after} /> <.currency_input id="amount-input" name="amount" value="20" unit="$" unit_position={:before} readonly />

Attributes

  • id (:any) - Defaults to nil.

  • name (:any)

  • label (:string) - Defaults to nil.

  • help_text (:string) - Defaults to nil.

  • value (:any)

  • field (Phoenix.HTML.FormField) - a form field struct retrieved from the form, for example: @form[:email].

  • errors (:list) - Defaults to [].

  • class (:any) - additional classes for the container element. Defaults to nil.

  • input_class (:any) - the input class to use over defaults, note that this is applied to a wrapper span element

          to allow for proper styling of the masked input

    Defaults to nil.

  • error_class (:any) - the input error class to use over defaults. Defaults to nil.

  • translate_error_fun (:any) - a custom function to map form errors. Defaults to &Function.identity/1.

  • hide_errors (:boolean) - if errors should be hidden. Defaults to false.

  • unit (:string) (required)

  • unit_position (:atom) (required) - Must be one of :before, or :after.

  • symbol_space (:atom) - Defaults to false.

  • radix (:string) - Defaults to ".".

  • thousands_separator (:string) - Defaults to ",".

  • Global attributes are accepted. Supports all globals plus: ["accept", "autocomplete", "capture", "cols", "disabled", "form", "list", "max", "maxlength", "min", "minlength", "multiple", "pattern", "placeholder", "readonly", "required", "rows", "size", "step"].

form_errors?(show_errors, form)

translate_form_errors(errors, translate_error_fun)