forked from CGM_Public/pretix_original
Fix checkbox-labels always containing text "required" although not being required
This commit is contained in:
committed by
GitHub
parent
21c273854c
commit
ca12cbb69e
@@ -60,8 +60,8 @@ def render_label(content, label_for=None, label_class=None, label_title='', labe
|
|||||||
# => remove for-attribute as well as "required"-text appended to label
|
# => remove for-attribute as well as "required"-text appended to label
|
||||||
if 'for' in attrs:
|
if 'for' in attrs:
|
||||||
del attrs['for']
|
del attrs['for']
|
||||||
else:
|
elif not optional:
|
||||||
opt += '<i class="sr-only label-required">, {}</i>'.format(pgettext('form', 'required')) if not optional else ''
|
opt += '<i class="sr-only label-required">, {}</i>'.format(pgettext('form', 'required'))
|
||||||
|
|
||||||
builder = '<{tag}{attrs}>{content}{opt}</{tag}>'
|
builder = '<{tag}{attrs}>{content}{opt}</{tag}>'
|
||||||
return format_html(
|
return format_html(
|
||||||
@@ -155,17 +155,28 @@ class CheckoutFieldRenderer(FieldRenderer):
|
|||||||
label_class=self.get_label_class(),
|
label_class=self.get_label_class(),
|
||||||
label_id=label_id,
|
label_id=label_id,
|
||||||
attrs=attrs,
|
attrs=attrs,
|
||||||
optional=not required and not isinstance(self.widget, CheckboxInput),
|
optional=not required,
|
||||||
is_valid=is_valid
|
is_valid=is_valid
|
||||||
) + html
|
) + html
|
||||||
return html
|
return html
|
||||||
|
|
||||||
def put_inside_label(self, html):
|
def put_inside_label(self, html):
|
||||||
content = "{field} {label}".format(field=html, label=self.label)
|
content = "{field} {label}".format(field=html, label=self.label)
|
||||||
|
|
||||||
|
if hasattr(self.field.field, '_show_required'):
|
||||||
|
# e.g. payment settings forms where a field is only required if the payment provider is active
|
||||||
|
required = self.field.field._show_required
|
||||||
|
elif hasattr(self.field.field, '_required'):
|
||||||
|
# e.g. payment settings forms where a field is only required if the payment provider is active
|
||||||
|
required = self.field.field._required
|
||||||
|
else:
|
||||||
|
required = self.field.field.required
|
||||||
|
|
||||||
return render_label(
|
return render_label(
|
||||||
content=mark_safe(content),
|
content=mark_safe(content),
|
||||||
label_for=self.field.id_for_label,
|
label_for=self.field.id_for_label,
|
||||||
label_title=escape(strip_tags(self.field_help)),
|
label_title=escape(strip_tags(self.field_help)),
|
||||||
|
optional=not required,
|
||||||
)
|
)
|
||||||
|
|
||||||
def wrap_label_and_field(self, html):
|
def wrap_label_and_field(self, html):
|
||||||
|
|||||||
Reference in New Issue
Block a user