Checkbox

New

Overview

Checkbox component to be used for boolean values in forms.

HEEx
<div class="stack grid gap-4.25">
  <Checkbox.checkbox
    id="example-updates"
    checked
    label="Product updates"
    description="Stores whether product updates are enabled."
  />
  <Checkbox.checkbox id="example-marketing" label="Product tips" />
</div>

Checkbox group

A checkbox group for selecting multiple values from one field, such as tags.

Tags

Choose every tag that applies.

HEEx
<div class="grid w-full gap-3">
  <Checkbox.checkbox_group
    id="example-tags"
    name="tags"
    label="Tags"
    description="Choose every tag that applies."
    options={[{"Design", "design"}, {"Engineering", "engineering"}, {"Research", "research"}]}
    value={["design", "research"]}
  />
</div>

Checkbox errors

When bound with field, validation errors render beneath the checkbox.

must be accepted

HEEx
<.form
  :let={form}
  for={to_form(%{"terms" => false}, errors: [terms: {"must be accepted", []}])}
  id="example-checkbox-errors-form"
  class="stack w-full"
>
  <Checkbox.checkbox field={form[:terms]} label="Accept the terms" />
</.form>

Checkbox group errors

When bound with field, validation errors render beneath the checkbox group.

Tags

can't be blank

HEEx
<.form
  :let={form}
  for={to_form(%{"tags" => []}, errors: [tags: {"can't be blank", []}])}
  id="example-checkbox-group-errors-form"
  class="w-full"
>
  <Checkbox.checkbox_group
    field={form[:tags]}
    label="Tags"
    options={[{"Design", "design"}, {"Engineering", "engineering"}, {"Research", "research"}]}
  />
</.form>

Add this module

terminal
mix dizzy.add checkbox

Component API

Checkbox.checkbox

Attributes

Attributes for Checkbox.checkbox
NameTypeDefault Values
checked :boolean false โ€”
checked_value :string "true" โ€”
class :any nil โ€”
description :string nil โ€”
disabled :boolean false โ€”
errors :list [] โ€”
field {:struct, Phoenix.HTML.FormField} nil โ€”
id :string nil โ€”
label :string nil โ€”
name :string nil โ€”
required :boolean false โ€”
rest :global nil โ€”
unchecked_value :string "false" โ€”

Checkbox.checkbox_group

Attributes

Attributes for Checkbox.checkbox_group
NameTypeDefault Values
class :any nil โ€”
description :string nil โ€”
disabled :boolean false โ€”
errors :list [] โ€”
field {:struct, Phoenix.HTML.FormField} nil โ€”
id :string nil โ€”
label :string nil โ€”
name :string nil โ€”
options :list Required โ€”
required :boolean false โ€”
rest :global nil โ€”
value :list [] โ€”