Checkbox
NewOverview
Checkbox component to be used for boolean values in forms.
<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.
<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.
<.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.
<.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
mix dizzy.add checkbox
Component API
Checkbox.checkbox
Attributes
| Name | Type | Default | 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
| Name | Type | Default | 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
| [] | โ |