Repository: zostera/django-bootstrap5

Issue:
RadioSelectButtonGroup doesn't render
Our custom widget doesn't render because the `template_name` is overwritten in `renderers.py`.


Discussion:
Same issue here, very annoying. beside that nice project
![r_on](https://user-images.githubusercontent.com/43114687/120892604-7b472000-c60f-11eb-982f-3d38b232bf27.png)
![r_off](https://user-images.githubusercontent.com/43114687/120892605-7da97a00-c60f-11eb-9874-fa36057195be.png)


How can I work around this issue?

Resolving patch:
diff --git a/src/django_bootstrap5/renderers.py b/src/django_bootstrap5/renderers.py
--- a/src/django_bootstrap5/renderers.py
+++ b/src/django_bootstrap5/renderers.py
@@ -19,7 +19,7 @@
 from .size import DEFAULT_SIZE, SIZE_MD, get_size_class, parse_size
 from .text import text_value
 from .utils import render_template_file
-from .widgets import ReadOnlyPasswordHashWidget, is_widget_with_placeholder
+from .widgets import RadioSelectButtonGroup, ReadOnlyPasswordHashWidget, is_widget_with_placeholder
 
 
 class BaseRenderer:
@@ -347,7 +347,9 @@ def add_widget_attrs(self):
         for widget in widgets:
             self.add_widget_class_attrs(widget)
             self.add_placeholder_attrs(widget)
-            if isinstance(widget, (RadioSelect, CheckboxSelectMultiple)):
+            if isinstance(widget, (RadioSelect, CheckboxSelectMultiple)) and not isinstance(
+                widget, RadioSelectButtonGroup
+            ):
                 widget.template_name = "django_bootstrap5/widgets/radio_select.html"
             elif isinstance(widget, ClearableFileInput):
                 widget.template_name = "django_bootstrap5/widgets/clearable_file_input.html"


Test patch:
diff --git a/tests/test_bootstrap_field_radio_select_button_group.py b/tests/test_bootstrap_field_radio_select_button_group.py
new file mode 100644
--- /dev/null
+++ b/tests/test_bootstrap_field_radio_select_button_group.py
@@ -0,0 +1,107 @@
+from django import forms
+
+from django_bootstrap5.widgets import RadioSelectButtonGroup
+
+from .base import BootstrapTestCase
+
+
+class SelectTestForm(forms.Form):
+    test = forms.ChoiceField(
+        choices=(
+            (1, "one"),
+            (2, "two"),
+        ),
+        widget=RadioSelectButtonGroup,
+    )
+
+
+class DisabledSelectTestForm(forms.Form):
+    test = forms.ChoiceField(
+        choices=(
+            (1, "one"),
+            (2, "two"),
+        ),
+        widget=RadioSelectButtonGroup,
+        disabled=True,
+    )
+
+
+class BootstrapFieldSelectTestCase(BootstrapTestCase):
+    def test_select(self):
+        """Test field with select widget."""
+        self.assertHTMLEqual(
+            self.render("{% bootstrap_field form.test %}", context={"form": SelectTestForm()}),
+            (
+                '<div class="django_bootstrap5-req mb-3">'
+                '<label class="form-label">Test</label>'
+                '<div id="id_test" class="btn-group" role="group">'
+                '<input type="radio" class=" btn-check" autocomplete="off" name="test" id="id_test_0" value="1" '
+                "required>"
+                '<label class="btn btn-outline-primary" for="id_test_0">one</label>'
+                '<input type="radio" class=" btn-check" autocomplete="off" name="test" id="id_test_1" value="2" '
+                "required>"
+                '<label class="btn btn-outline-primary" for="id_test_1">two</label>'
+                "</div>"
+                "</div>"
+            ),
+        )
+
+    def test_select_horizontal(self):
+        """Test field with select widget in horizontal layout."""
+        self.assertHTMLEqual(
+            self.render('{% bootstrap_field form.test layout="horizontal" %}', context={"form": SelectTestForm()}),
+            (
+                '<div class="django_bootstrap5-req row mb-3">'
+                '<label class="col-sm-2 col-form-label">Test</label>'
+                '<div class="col-sm-10">'
+                '<div id="id_test" class="btn-group" role="group">'
+                '<input type="radio" class=" btn-check" autocomplete="off" name="test" id="id_test_0" value="1" '
+                "required>"
+                '<label class="btn btn-outline-primary" for="id_test_0">one</label>'
+                '<input type="radio" class=" btn-check" autocomplete="off" name="test" id="id_test_1" value="2" '
+                "required>"
+                '<label class="btn btn-outline-primary" for="id_test_1">two</label>'
+                "</div>"
+                "</div>"
+                "</div>"
+            ),
+        )
+
+    def test_select_floating(self):
+        """Test field with select widget in floating layout."""
+        self.assertHTMLEqual(
+            self.render('{% bootstrap_field form.test layout="floating" %}', context={"form": SelectTestForm()}),
+            (
+                '<div class="django_bootstrap5-req mb-3">'
+                '<label class="form-label">Test</label>'
+                '<div id="id_test" class="btn-group" role="group">'
+                '<input type="radio" class=" btn-check" autocomplete="off" name="test" id="id_test_0" value="1" '
+                "required>"
+                '<label class="btn btn-outline-primary" for="id_test_0">one</label>'
+                '<input type="radio" class=" btn-check" autocomplete="off" name="test" id="id_test_1" value="2" '
+                "required>"
+                '<label class="btn btn-outline-primary" for="id_test_1">two</label>'
+                "</div>"
+                "</div>"
+            ),
+        )
+
+    def test_disabled_select(self):
+        """Test field with disabled select widget."""
+        self.maxDiff = None
+        self.assertHTMLEqual(
+            self.render("{% bootstrap_field form.test %}", context={"form": DisabledSelectTestForm()}),
+            (
+                '<div class="django_bootstrap5-req mb-3">'
+                '<label class="form-label">Test</label>'
+                '<div id="id_test" class="btn-group" role="group">'
+                '<input type="radio" class=" btn-check" autocomplete="off" name="test" id="id_test_0" value="1" '
+                "disabled required>"
+                '<label class="btn btn-outline-primary" for="id_test_0">one</label>'
+                '<input type="radio" class=" btn-check" autocomplete="off" name="test" id="id_test_1" value="2" '
+                "disabled required>"
+                '<label class="btn btn-outline-primary" for="id_test_1">two</label>'
+                "</div>"
+                "</div>"
+            ),
+        )