diff --git a/hshassets/forms/utils.py b/hshassets/forms/utils.py index b270675dce2f5014d81949d0812a65f6f31c52d5..efc23b885684345d7dd2e0d02297188b66bc4d38 100644 --- a/hshassets/forms/utils.py +++ b/hshassets/forms/utils.py @@ -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">""" - return format_html('<label for="{}" class="{}">{}</label> {}', for_id, css_class, label, content) + + 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, ) -