Skip to content
Snippets Groups Projects
Commit 3dbb95f6 authored by Tim Fechner's avatar Tim Fechner
Browse files

Don't output empty <label for=""> attributes

parent eb75b520
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ def render_form_field(field):
input_type = field.field.widget.input_type
except AttributeError:
input_type = None
if input_type in ['text', 'number', 'email', 'url', 'password']:
# one of those text-like that support icons
out = BulmaFieldMarkup.label(field.label, BulmaFieldMarkup.with_icons(field, field.as_widget()))
......@@ -17,6 +18,7 @@ def render_form_field(field):
else:
# fallback default
out = BulmaFieldMarkup.label(field.label, BulmaFieldMarkup.div_control(field.as_widget()))
return BulmaFieldMarkup.div_field(field, out)
......@@ -43,7 +45,12 @@ class BulmaFieldMarkup(object):
@classmethod
def label(cls, label, content='', css_class='label', for_id=''):
"""Define <label> seperately so it can be used elsewhere instead as a children of the <div class="field">"""
if for_id:
return format_html('<label for="{}" class="{}">{}</label> {}', for_id, css_class, label, content)
else:
# don't output a empty for="" attribute as it breaks some form functionality
return format_html('<label class="{}">{}</label> {}', css_class, label, content)
@classmethod
def with_icons(cls, field, content):
......@@ -126,4 +133,3 @@ def render_form_errors(errors):
""",
error_tags=error_tags,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment