Repository: zostera/django-bootstrap4

Issue:
Feature request: Allow to skip label from field completely
```
{% bootstrap_field field show_label=False %}
```

currently still renders the label, but with `class="sr-only"`. This is great for most cases, but it is actually a bad idea if the users manually adds the label separately. In that case, both labels will be associated with the form field and the computed aria-label will be "{label} {label}".


Discussion:
I agree on this. Can you propose an API for this using a pull request?
A straigtforward API would be `show_label=True|False|'sr-only'`, but that would be a breaking change.

Maybe `show_label='default'|'sr-only'|'hidden'` where `True` maps to `'default'` and `False` maps to `'sr-only'`  for backwards compatibility.
Not sure about 'hidden' since it implies the current `False` to me...

Resolving patch:
diff --git a/bootstrap4/renderers.py b/bootstrap4/renderers.py
--- a/bootstrap4/renderers.py
+++ b/bootstrap4/renderers.py
@@ -533,12 +533,14 @@ def get_label_class(self):
             label_class = self.horizontal_label_class
             label_class = add_css_class(label_class, "col-form-label")
         label_class = text_value(label_class)
-        if not self.show_label:
+        if not self.show_label or self.show_label == "sr-only":
             label_class = add_css_class(label_class, "sr-only")
         return label_class
 
     def get_label(self):
-        if isinstance(self.widget, CheckboxInput):
+        if self.show_label == "skip":
+            return None
+        elif isinstance(self.widget, CheckboxInput):
             label = None
         else:
             label = self.field.label
diff --git a/bootstrap4/templatetags/bootstrap4.py b/bootstrap4/templatetags/bootstrap4.py
--- a/bootstrap4/templatetags/bootstrap4.py
+++ b/bootstrap4/templatetags/bootstrap4.py
@@ -529,6 +529,10 @@ def bootstrap_field(*args, **kwargs):
         show_label
             Whether the show the label of the field.
 
+                * ``True``
+                * ``False``/``'sr-only'``
+                * ``'skip'``
+
             :default: ``True``
 
         exclude


Test patch:
diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py
--- a/tests/test_templatetags.py
+++ b/tests/test_templatetags.py
@@ -770,13 +770,27 @@ def test_button(self):
 
 
 class ShowLabelTest(TestCase):
-    def test_show_label(self):
+    def test_show_label_false(self):
         form = TestForm()
         res = render_template_with_form(
             "{% bootstrap_form form show_label=False %}", {"form": form}
         )
         self.assertIn("sr-only", res)
 
+    def test_show_label_sr_only(self):
+        form = TestForm()
+        res = render_template_with_form(
+            "{% bootstrap_form form show_label='sr-only' %}", {"form": form}
+        )
+        self.assertIn("sr-only", res)
+
+    def test_show_label_skip(self):
+        form = TestForm()
+        res = render_template_with_form(
+            "{% bootstrap_form form show_label='skip' %}", {"form": form}
+        )
+        self.assertNotIn("<label>", res)
+
     def test_for_formset(self):
         TestFormSet = formset_factory(TestForm, extra=1)
         test_formset = TestFormSet()