I have a front-end that generates bootstrap forms via a simple macro:
{% macro render_field(field, class_='', label_visible=true) -%}
<div class="form-group {% if field.errors %} has-error {% endif %}">
{% if (field.type != 'HiddenField' and field.type !='CSRFTokenField') and label_visible %}
<label for="{{ field.id }}" class="control-label">{{ field.label }}</label>
{% endif %}
{{ field(class_='form-control', **kwargs) }}
{% if field.errors %}
{% for e in field.errors %}
<p class="help-block">{{ e }}</p>
{% endfor %}
{% endif %}
</div>
{%- endmacro %}
A wtform that I use looks like this:
class CommentForm(Form):
comment = TextAreaField(validators=[DataRequired('Please enter your comment.')])
Is it possible to add front-end validation in the form of aria-required="true"
for the fields that have as validator DataRequired
?
If so, how?