LanternUI.Components.Checkbox (LanternUI v0.8.2)

Copy Markdown View Source

Checkbox with label, description, and error states.

<.checkbox field={@form[:accept]} label="Accept the terms" />
<.checkbox name="notify" checked={@notify} label="Email me" description="At most one per day." />

The API mirrors Fluxon's checkbox/1 (field/name/checked, checked_value/unchecked_value, label/sublabel/description, errors), so a use Fluxon app can swap imports without template changes. A hidden input submits unchecked_value when the box is unchecked, so forms always receive the param. (checkbox_group/1 is not yet implemented.)

Summary

Functions

checkbox(assigns)

Attributes

  • id (:any) - Element id; derived from field when omitted. Defaults to nil.
  • name (:string) - Form input name; derived from field when omitted. Defaults to nil.
  • value (:any) - Current value used to derive checked state. Defaults to nil.
  • checked (:boolean) - Force checked state; else compares value to checked_value. Defaults to nil.
  • checked_value (:any) - Value submitted when the box is checked. Defaults to "true".
  • unchecked_value (:any) - Hidden input value submitted when unchecked. Defaults to "false".
  • label (:string) - Primary label text beside the control. Defaults to nil.
  • sublabel (:string) - Secondary label line under the primary label. Defaults to nil.
  • description (:string) - Helper text under the label stack. Defaults to nil.
  • errors (:list) - Validation messages; derived from field when used. Defaults to [].
  • class (:any) - Extra classes merged onto the root element. Defaults to nil.
  • field (Phoenix.HTML.FormField) - Form field; derives id, name, value, and errors. Defaults to nil.
  • disabled (:boolean) - Render disabled and non-interactive. Defaults to false.
  • Global attributes are accepted. Arbitrary HTML/phx-* attributes passed through.