replace FieldBlock rendering with a template-based version that tries to replicate our standard form field markup

This commit is contained in:
Matt Westcott 2015-01-13 14:55:55 +00:00
parent 622762f0e2
commit 3386ee53e6
2 changed files with 33 additions and 5 deletions

View file

@ -218,10 +218,10 @@ class FieldBlock(Block):
widget_html = widget.render(prefix, value, {'id': prefix})
if error:
error_html = str(ErrorList(error.error_list))
else:
error_html = ''
#if error:
# error_html = str(ErrorList(error.error_list))
#else:
# error_html = ''
if self.label:
label_html = format_html(
@ -231,7 +231,12 @@ class FieldBlock(Block):
else:
label_html = ''
return mark_safe(error_html + label_html + widget_html)
return render_to_string('wagtailadmin/block_forms/field.html', {
'widget': widget_html,
'label_tag': label_html,
'field': self.field,
'errors': error.error_list if error else [], # TODO: should this be ErrorList(error.error_list)?
})
def value_from_datadict(self, data, files, prefix):
return self.field.widget.value_from_datadict(data, files, prefix)

View file

@ -0,0 +1,23 @@
{% load wagtailadmin_tags %}
<div class="field {{ field|fieldtype }}">
{{ field.label_tag }}
<div class="field-content">
<div class="input">
{{ widget }}
{# This span only used on rare occasions by certain types of input #}
<span></span>
</div>
{% if field.help_text %}
<p class="help">{{ field.help_text }}</p>
{% endif %}
{% if errors %}
<p class="error-message">
{% for error in errors %}
<span>{{ error|escape }}</span>
{% endfor %}
</p>
{% endif %}
</div>
</div>