Django-bootstrap3: Label generated with show_label=False with checkbox

Created on 28 Jul 2017  ·  8Comments  ·  Source: zostera/django-bootstrap3

{% bootstrap_field form.statut form_group_class='col-md-6' show_label=False %}
The form.statut field is a checkbox
Html Result :
<div class="col-md-6">
    <div class="checkbox">
         <label for="id_statut">
        <input name="statut" class="" required="" id="id_statut" type="checkbox"> J'adhère aux
        <a href="url_statuts.pdf" target="_blank">statuts</a>
         </label>
     </div>
</div>

show_label has no effect. The source of the issue is maybe:
FieldRenderer.put_inside_label() in post_widget_render() with CheckBoxInput (renderers.py)

bug wontfix

Most helpful comment

@dyve
It can be solved when adding "label_class=self.get_label_class()" to the function below

def put_inside_label(self, html):
        content = '{field} {label}'.format(
            field=html,
            label=self.label,
        )
        return render_label(
            content=mark_safe(content),
            label_for=self.field.id_for_label,
            label_title=escape(strip_tags(self.field_help)),
            label_class=self.get_label_class()
        )

This function is located in "bootstrap3 / renderers.py"

All 8 comments

Thanks, looks like a bug. You've done some investigating already. A Pull Request with a test case would be very welcome.

The bug is real.
Is the fix coming anytime soon?

@donvito-pl @kutera any chance you can submit a pull request for this?

Will try to investigate, but odds of succeeding not that high :)

"addon_before, label_class and field_class" also don't work with checkbox.
So checkbox field is can't be used as custom field.

@dyve
It can be solved when adding "label_class=self.get_label_class()" to the function below

def put_inside_label(self, html):
        content = '{field} {label}'.format(
            field=html,
            label=self.label,
        )
        return render_label(
            content=mark_safe(content),
            label_for=self.field.id_for_label,
            label_title=escape(strip_tags(self.field_help)),
            label_class=self.get_label_class()
        )

This function is located in "bootstrap3 / renderers.py"

@nikolaysm

This is hiding the checkbox to.

Maybe something like this:

def put_inside_label(self, html):
        content = '{field} {label}'.format(
            field=html,
            >>>> label=self.label if self.show_label else ''
        )
        return render_label(
            content=mark_safe(content),
            label_for=self.field.id_for_label,
            label_title=escape(strip_tags(self.field_help))
        )

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jayvdb picture jayvdb  ·  7Comments

radzhome picture radzhome  ·  4Comments

Macainian picture Macainian  ·  6Comments

dwt picture dwt  ·  3Comments

chuma picture chuma  ·  3Comments