Files
notifications-admin/app/templates/components/textbox.html
Chris Hill-Scott d5edb8dbfb Track form validation errors in Google analytics
We started tracking upload errors in eb264f34b7

This has been useful.

This commit adds tracking of other form validation errors, so we can
pick up if there’s a form field that’s causing people particular
trouble.

Also had to rewrite a very old test to look for page content in a
smarter way.
2017-10-16 15:26:21 +01:00

59 lines
1.7 KiB
HTML

{% macro textbox(
field,
label=None,
hint=False,
highlight_tags=False,
autofocus=False,
help_link=None,
help_link_text=None,
width='2-3',
suffix=None,
safe_error_message=False,
rows=8
) %}
<div class="form-group{% if field.errors %} form-group-error{% endif %}" {% if autofocus %}data-module="autofocus"{% endif %}>
<label class="form-label" for="{{ field.name }}">
{% if label %}
{{ label }}
{% else %}
{{ field.label.text }}
{% endif %}
{% if hint %}
<span class="form-hint">
{{ hint }}
</span>
{% endif %}
{% if field.errors %}
<span class="error-message" data-module="track-error" data-error-type="{{ field.errors[0] }}" data-error-label="{{ field.name }}">
{% if not safe_error_message %}{{ field.errors[0] }}{% else %}{{ field.errors[0]|safe }}{% endif %}
</span>
{% endif %}
</label>
{%
if highlight_tags
%}
{% set field_class = 'form-control-{} textbox-highlight-textbox'.format(width) %}
{% else %}
{% set field_class = 'form-control-{} {}'.format(width, 'textbox-right-aligned' if suffix else '') %}
{% endif %}
{%
set field_class = 'form-control ' + field_class + (
' form-control-error' if field.errors else ''
)
%}
{{ field(**{
'class': field_class,
'data-module': 'highlight-tags' if highlight_tags else '',
'rows': rows|string
}) }}
{% if suffix %}
<span>{{ suffix }}</span>
{% endif %}
{% if help_link and help_link_text %}
<p class="textbox-help-link">
<a href='{{ help_link }}'>{{ help_link_text }}</a>
</p>
{% endif %}
</div>
{% endmacro %}