Pax.Field.Components (Pax v0.0.1-dev)

View Source

Summary

Functions

Renders an input control for the given field and form_field. This is for use by Pax.Field implementations. As such, it requires a field and form_field, and will render the appropriate input control for the field type.

Renders a single field error.

Renders a list of errors for the given Pax.Field. The errors are rendered using the <.pax_field_error> component.

Renders an input control for the given field and form, as well as any errors for the field. The input control is determined by the field type, as the type's input/3 is called, which will render the appropriate input control for the field type. The errors are rendered using the pax_field_errors/1 function, which will render any errors for the field.

Renders a field input or text for the given Pax.Field. If the field is immutable, or if no form is set, then a <.pax_field_text class={@text_class} ...> is rendered. Otherwise, a <.pax_field_input class={@input_class} ...> is rendered.

Renders a label for the given Pax.Field. If the Pax.Field has a :label option set, it will be used as the label text, otherwise the field name will be used. The :for option can be used to set the for attribute of the label, otherwise the :form will be used if set, and finally the field name will be used.

Renders a link for the given Pax.Field, similar to pax_field_text/1, but wrapped in a <.pax_link> component. The link will use the navigate attribute, which results in patches to the same LiveView, navigates to different LiveViews in the same live_session, and finally a normal, full page navigation to other URLs.

Renders a link or text for the given Pax.Field. A link is rendered if the field has a valid :link option set.

Renders the :value of the given Pax.Field as plain text. The field's value will be resolved depending on what it is set to, calling any functions or using any other field names as required. Otherwise it will find the value in the object map by the field name. A nil value will be rendered as a unicode bullet character (, U+2022).

Functions

pax_field_control(assigns)

Renders an input control for the given field and form_field. This is for use by Pax.Field implementations. As such, it requires a field and form_field, and will render the appropriate input control for the field type.

The form_field is used to retrieve the input name, id and values, however they can be overridden by passing them 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.

Examples

<.input field={@form[:email]} type="email" />
<.input name="my-input" errors={["oh no!"]} />

Attributes

  • field (:any) (required)
  • form_field (Phoenix.HTML.FormField)
  • id (:any) - Defaults to nil.
  • name (:any)
  • label (:string) - Defaults to nil.
  • value (:any)
  • has_errors (:boolean) - Defaults to false.
  • type (:string) - Defaults to "text". Must be one of "checkbox", "color", "date", "datetime-local", "email", "file", "hidden", "month", "number", "password", "range", "radio", "search", "select", "tel", "text", "textarea", "time", "url", or "week".
  • 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.
  • true_value (:string) - the value to display for true checkboxes. Defaults to "True".
  • false_value (:string) - the value to display for false checkboxes. 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"].

pax_field_error(assigns)

Renders a single field error.

Attributes

  • class (:any) - Defaults to nil.

Slots

  • inner_block (required)

pax_field_errors(assigns)

Renders a list of errors for the given Pax.Field. The errors are rendered using the <.pax_field_error> component.

Attributes

  • errors (:list)
  • field (:any) (required)
  • form (:any) - Defaults to nil.
  • class (:any) - Defaults to nil.
  • error_class (:string) - Defaults to nil.

pax_field_input(assigns)

Renders an input control for the given field and form, as well as any errors for the field. The input control is determined by the field type, as the type's input/3 is called, which will render the appropriate input control for the field type. The errors are rendered using the pax_field_errors/1 function, which will render any errors for the field.

Attributes

  • field (:any) (required)
  • form (:any) (required)
  • object (:any) (required)
  • class (:any) - Defaults to nil.
  • text_class (:any) - Defaults to nil.
  • errors_class (:any) - Defaults to nil.
  • error_class (:any) - Defaults to nil.

pax_field_input_or_text(assigns)

Renders a field input or text for the given Pax.Field. If the field is immutable, or if no form is set, then a <.pax_field_text class={@text_class} ...> is rendered. Otherwise, a <.pax_field_input class={@input_class} ...> is rendered.

Attributes

  • field (:any) (required)
  • form (:any) - Defaults to nil.
  • object (:any) (required)
  • input_class (:any) - Defaults to nil.
  • text_class (:any) - Defaults to nil.
  • errors_class (:any) - Defaults to nil.
  • error_class (:any) - Defaults to nil.

pax_field_label(assigns)

Renders a label for the given Pax.Field. If the Pax.Field has a :label option set, it will be used as the label text, otherwise the field name will be used. The :for option can be used to set the for attribute of the label, otherwise the :form will be used if set, and finally the field name will be used.

Attributes

  • field (:any) (required)
  • form (:any) - Defaults to nil.
  • label (:string) - Defaults to nil.
  • for (:string) - Defaults to nil.
  • class (:any) - Defaults to nil.

pax_field_link(assigns)

Renders a link for the given Pax.Field, similar to pax_field_text/1, but wrapped in a <.pax_link> component. The link will use the navigate attribute, which results in patches to the same LiveView, navigates to different LiveViews in the same live_session, and finally a normal, full page navigation to other URLs.

Attributes

  • field (:any) (required)
  • object (:map) (required)
  • link (:string) (required)
  • class (:any) - Defaults to nil.

pax_field_text(assigns)

Renders the :value of the given Pax.Field as plain text. The field's value will be resolved depending on what it is set to, calling any functions or using any other field names as required. Otherwise it will find the value in the object map by the field name. A nil value will be rendered as a unicode bullet character (, U+2022).

Attributes

  • field (:any) (required)
  • object (:map) (required)
  • class (:any) - Defaults to nil.