View Source DaisyUIComponents.Form (DaisyUIComponents v0.6.0)

Form component helpers

Summary

Functions

Generates a generic error message.

Renders an input with label and error messages.

Renders a label.

Renders a simple form. This component was extracted from the original Phoenix CoreComponents.

Functions

error(assigns)

Generates a generic error message.

Attributes

Slots

  • inner_block

form_input(assigns)

Renders an input with label and error messages.

A %Phoenix.HTML.Form{} and field name may be passed to the input to build input names and error messages, or all the attributes and errors may be passed explicitly.

Examples

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

Attributes

  • id (:any) - Defaults to nil.
  • name (:any)
  • label (:string) - Defaults to nil.
  • value (:any)
  • color (:string) - Defaults to nil.
  • type (:string) - Defaults to "text".
  • field (Phoenix.HTML.FormField) - a form field struct retrieved from the form, for example: @form[:email].
  • class (:string) - Defaults to nil.
  • bordered (:boolean) - Defaults to true.
  • 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.
  • Global attributes are accepted. Supports all globals plus: ["autocomplete", "cols", "disabled", "form", "list", "max", "maxlength", "min", "minlength", "pattern", "placeholder", "readonly", "required", "rows", "size", "step"].

Slots

  • inner_block

label(assigns)

Renders a label.

Attributes

  • class (:any) - Defaults to nil.
  • for (:string) - Defaults to nil.
  • type (:string) - Defaults to "label".
  • label (:string) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block

simple_form(assigns)

Renders a simple form. This component was extracted from the original Phoenix CoreComponents.

Examples

<.simple_form for={@form} phx-change="validate" phx-submit="save">
  <.input field={@form[:email]} label="Email"/>
  <.input field={@form[:username]} label="Username" />
  <:actions>
    <.button>Save</.button>
  </:actions>
</.simple_form>

Attributes

  • for (:any) (required) - the datastructure for the form.
  • as (:any) - the server side parameter to collect all input under. Defaults to nil.
  • Global attributes are accepted. the arbitrary HTML attributes to apply to the form tag. Supports all globals plus: ["autocomplete", "name", "rel", "action", "enctype", "method", "novalidate", "target"].

Slots

  • inner_block (required)
  • actions - the slot for form actions, such as a submit button.