Skip to content

Commit

Permalink
Update RadioSelectButtonGroup() with form validation and non-horizont…
Browse files Browse the repository at this point in the history
…al alignment.
  • Loading branch information
danniranderis committed Oct 25, 2024
1 parent fd36574 commit f935b50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
2 changes: 0 additions & 2 deletions docs/widgets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ A form widget is available for displaying radio buttons as a Bootstrap 5 button
RadioSelectButtonGroup
~~~~~~~~~~~~~~~~~~~~~~

*Known issue: This widget currently renders as a regular Bootstrap 5 RadioSelect.*

This renders a form ChoiceField as a Bootstrap 5 button group in the `primary` Bootstrap 5 color.

.. code:: django
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<div{% if widget.attrs.id %} id="{{ widget.attrs.id }}"{% endif %} class="btn-group" role="group">
{% for group, options, index in widget.optgroups %}
{% for option in options %}
<input type="{{ option.type }}"
class="{{ widget.attrs.class|add:' btn-check' }}"
autocomplete="off"
name="{{ option.name }}"
id="{{ option.attrs.id }}"
{% if option.value != None %} value="{{ option.value|stringformat:'s' }}"
{% if option.attrs.checked %} checked="checked"{% endif %}{% endif %}
{% if widget.attrs.disabled %} disabled{% endif %}
{% if widget.required %} required{% endif %}>
<label class="btn btn-outline-primary" for="{{ option.attrs.id }}">{{ option.label }}</label>
{% endfor %}
{% endfor %}
{% load django_bootstrap5 %}
{% bootstrap_server_side_validation_class widget as server_side_validation_class %}
<div{% include "django/forms/widgets/attrs.html" %}>
<div class="btn-group" role="group">
{% for group, options, index in widget.optgroups %}
{% for option in options %}
<input type="{{ option.type }}"
class="{{ widget.attrs.class|add:' btn-check' }}"
autocomplete="off"
name="{{ option.name }}"
id="{{ option.attrs.id }}"
{% if option.value != None %} value="{{ option.value|stringformat:'s' }}"
{% if option.attrs.checked %} checked="checked"{% endif %}{% endif %}
{% if widget.attrs.disabled %} disabled{% endif %}
{% if widget.required %} required{% endif %}>
<label class="btn btn-outline-primary" for="{{ option.attrs.id }}">{{ option.label }}</label>
{% endfor %}
{% endfor %}
</div>
</div>

0 comments on commit f935b50

Please sign in to comment.