Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Toggle Radio and Checkbox #190

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crispy_bootstrap5/bootstrap5.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ def __init__(self, *args, **kwargs):

class Switch(Field):
template = "bootstrap5/layout/switch.html"

class Toggle(Field):
template = "bootstrap5/layout/toggle.html"
24 changes: 24 additions & 0 deletions crispy_bootstrap5/templates/bootstrap5/layout/toggle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% load crispy_forms_filters %}
{% load l10n %}

<div{% if wrapper_class %} class="{{ wrapper_class }}"{% endif %}>
{% for group, options, index in field|optgroups %}
{% if group %}<strong>{{ group }}</strong>{% endif %}
{% for option in options %}
<input type="{{ option.type }}" class="btn-check{% if field.errors %} is-invalid{% endif %}" name="{{ field.html_name }}" value="{{ option.value|unlocalize }}" {% include "bootstrap5/layout/attrs.html" with widget=option %}>
<label for="{{ option.attrs.id }}" class="{% if option.attrs.class %}{{ option.attrs.class }}{% else %}btn btn-outline-primary{% endif %}">
{{ option.label|unlocalize }}
</label>
{% if field.errors and forloop.last and not inline_class and forloop.parentloop.last %}
{% include 'bootstrap5/layout/field_errors_block.html' %}
{% endif %}
{% endfor %}
{% endfor %}
</div>

{% if field.errors and inline_class %}
{% for error in field.errors %}
<p id="error_{{ forloop.counter }}_{{ field.auto_id }}" class="invalid-feedback"><strong>{{ error }}</strong></p>
{% endfor %}
{% endif %}
{% include 'bootstrap5/layout/help_text.html' %}