Checkbox
NewOverview
Checkbox component to be used for boolean values in forms.
Stores whether product updates are enabled.
<.form for={@form}>
<div class="grid gap-4">
<Checkbox.checkbox
field={@form[:product_updates]}
label="Product updates"
sublabel="Recommended"
description="Stores whether product updates are enabled."
/>
<Checkbox.checkbox field={@form[:product_tips]} label="Product tips" />
</div>
</.form>
Checkbox group
A checkbox group for selecting multiple values from one field, such as tags.
<.form for={@form}>
<Checkbox.checkbox_group
field={@form[:tags]}
label="Tags"
description="Choose every tag that applies."
options={[{"Design", "design"}, {"Engineering", "engineering"}, {"Research", "research"}]}
/>
</.form>
Checkbox errors
When bound with field, validation errors render beneath the
checkbox input
.
<.form for={@form}>
<Checkbox.checkbox field={@form[:terms]} label="Accept the terms" />
</.form>
Checkbox group errors
When bound with field, validation errors render beneath the
group of checkbox input elements
.
<.form for={@form}>
<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 | โ |
sublabel |
:string
| 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
| [] | โ |