Checkbox
Preview
You agree to our terms of service.
Usage
views.py
python
from djust import LiveView
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.name = 'gallery_checkbox'my_template.html
django
{% load theme_components %}
{% theme_checkbox name=name label='Accept terms' description='You agree to our terms of service.' %}Props
| Name | Type | Required | Default |
|---|---|---|---|
| name | str | required | — |
| label | str | — | |
| description | Optional[str] | — | |
| css_prefix | str | — | |
| attrs | dict | — | |
| slot_label | str | — | |
| slot_description | str | — |
Accessibility
| Requirement | Element | Attribute | Value |
|---|---|---|---|
| Label must reference checkbox via for attribute | label | for | (present) |
Slots
slot_label slot_description
Source & styles
| File | Path | Notes |
|---|---|---|
| template | djust_theming/components/checkbox.html | Copy it to the same path in your project, or per theme under djust_theming/themes/<theme>/components/. |
Template source — checkbox.html
django
<div class="{{ css_prefix }}checkbox-group {% if attrs.class %}{{ attrs.class }}{% endif %}">
<input
type="checkbox"
name="{{ name }}"
id="{{ name }}"
class="{{ css_prefix }}checkbox"
{% if attrs.checked %}checked{% endif %}
{% if attrs.required %}required{% endif %}
{% if attrs.disabled %}disabled{% endif %}
{% if attrs.value %}value="{{ attrs.value }}"{% endif %}
/>
{% if slot_label %}
{{ slot_label|safe }}
{% elif label %}
<label for="{{ name }}" class="{{ css_prefix }}checkbox-label">{{ label }}</label>
{% endif %}
{% if slot_description %}
<div class="{{ css_prefix }}checkbox-description">{{ slot_description|safe }}</div>
{% elif description %}
<div class="{{ css_prefix }}checkbox-description">{{ description }}</div>
{% endif %}
</div>