ZoonkWeb.Components.Input (Zoonk v0.1.0-dev)

View Source

Provides the UI for rendering input fields.

Summary

Functions

Generates a generic error message.

Renders an input with label and error messages.

Renders a label.

Translates an error message using gettext.

Translates the errors for a field from a keyword list of errors.

Functions

error(assigns)

Generates a generic error message.

Slots

  • inner_block (required)

input(assigns)

Renders an input with label and error messages.

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.

Types

This function accepts all HTML input types, considering that:

  • You may also set type="select" to render a <select> tag

  • type="checkbox" is used exclusively to render boolean values

  • For live file uploads, see Phoenix.Component.live_file_input/1

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input for more information. Unsupported types, such as hidden and radio, are best written directly in your templates.

Examples

<.input field={@form[:email]} type="email" />
<.input name="my-input" errors={["oh no!"]} />
<.input name="search" show_submit placeholder="Search..." />
<.input name="search-custom" show_submit submit_icon="tabler-search" placeholder="Search..." />

Attributes

  • id (:any) - Defaults to nil.
  • name (:any)
  • label (:string) - Defaults to nil.
  • value (:any)
  • class (:any) - additional classes to apply to the input. Defaults to nil.
  • hide_label (:boolean) - if true, the label will be hidden - used only for screen readers. Defaults to false.
  • type (:string) - Defaults to "text". Must be one of "checkbox", "color", "date", "datetime-local", "email", "file", "hidden", "month", "number", "password", "range", "search", "select", "tel", "text", "textarea", "time", "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.
  • submit_icon (:string) - The Tabler icon name to use for the submit button. Defaults to nil.
  • 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"].

label(assigns)

Renders a label.

Attributes

  • for (:string) - Defaults to nil.
  • hide_label (:boolean) - Defaults to false.

Slots

  • inner_block (required)

translate_error(arg)

Translates an error message using gettext.

translate_errors(errors, field)

Translates the errors for a field from a keyword list of errors.