Forms.checkbox
Server-rendered
Renders a checkbox control with optional inline label content.
Basic checkbox
<.checkbox id="terms" name="terms">Accept terms</.checkbox>
Checked state
<.checkbox id="updates" name="updates" checked={true}>Notify me about product updates</.checkbox>
With FormField
Phoenix shim
<.checkbox field={@form[:active]} />
With label attr (inline)
Phoenix shim
<.checkbox field={@form[:active]} label="Active" />
With inner_block (takes precedence over label attr)
Phoenix shim
<.checkbox field={@form[:terms]}>
I agree to the <a href="/terms">Terms of Service</a>
</.checkbox>
With explicit errors
Phoenix shimmust be accepted
<.checkbox field={@form[:terms]} errors={["must be accepted"]} />
Inside field composition
Phoenix shim
<.field>
<:label for={@form[:active].id}>Active</:label>
<.checkbox field={@form[:active]} />
</.field>
Attributes
| Name | Type | Default | Values | Global Includes |
|---|---|---|---|---|
checked
|
:boolean |
false
|
— | — |
class
|
:string |
— | — | — |
disabled
|
:boolean |
false
|
— | — |
errors
|
:list |
— | — | — |
field
|
{:struct, Phoenix.HTML.FormField} |
— | — | — |
id
|
:string |
— | — | — |
label
|
:string |
— | — | — |
name
|
:string |
— | — | — |
rest
|
:global |
— | — | — |
value
|
:string |
"true"
|
— | — |
Slots
| Slot | Slot Attributes |
|---|---|
inner_block
|
— |