Use simple field labels when possible

only use template if it must include icons etc.
This commit is contained in:
Lance Edgar 2024-04-25 22:49:37 -05:00
parent 2a22e8939c
commit 8b3a9c9dad

View file

@ -1093,15 +1093,23 @@ class Form(object):
label_contents.append(HTML.literal('   ')) label_contents.append(HTML.literal('   '))
label_contents.append(icon) label_contents.append(icon)
# only declare label template if it's complex
html = [html]
if len(label_contents) > 1:
# nb. must apply hack to get <template #label> as final result # nb. must apply hack to get <template #label> as final result
label_template = HTML.tag('template', c=label_contents, label_template = HTML.tag('template', c=label_contents,
**{'#label': 1}) **{'#label': 1})
label_template = label_template.replace( label_template = label_template.replace(
HTML.literal('<template #label="1"'), HTML.literal('<template #label="1"'),
HTML.literal('<template #label')) HTML.literal('<template #label'))
html.insert(0, label_template)
else: # simple label
attrs['label'] = label
# and finally wrap it all in a <b-field> # and finally wrap it all in a <b-field>
return HTML.tag('b-field', c=[label_template, html], **attrs) return HTML.tag('b-field', c=html, **attrs)
elif field: # hidden field elif field: # hidden field