Add validation flag if field is required.

This commit is contained in:
Patrick Jentsch 2020-04-20 11:12:20 +02:00
parent 339107fd08
commit 8a9db7f4b8

View File

@ -1,11 +1,27 @@
{% macro render_field(field) %} {% macro render_field(field) %}
{% if field.flags.required %}
{% if 'class_' in kwargs and 'validate' not in kwargs['class_'] %}
{% set tmp = kwargs.update({'class_': kwargs['class_'] + ' validate'}) %}
{% else %}
{% set tmp = kwargs.update({'class_': 'validate'}) %}
{% endif %}
{% endif %}
{% if field.type == 'BooleanField' %} {% if field.type == 'BooleanField' %}
{{ render_boolean_field(field, *args, **kwargs) }} {{ render_boolean_field(field, *args, **kwargs) }}
{% elif field.type == 'IntegerField' %}
{% set tmp = kwargs.update({'type': 'number'}) %}
{% if 'class_' in kwargs and 'validate' not in kwargs['class_'] %}
{% set tmp = kwargs.update({'class_': kwargs['class_'] + ' validate'}) %}
{% else %}
{% set tmp = kwargs.update({'class_': 'validate'}) %}
{% endif %}
{{ render_generic_field(field, *args, **kwargs) }}
{% elif field.type == 'SubmitField' %} {% elif field.type == 'SubmitField' %}
{{ render_submit_field(field, *args, **kwargs) }} {{ render_submit_field(field, *args, **kwargs) }}
{% elif field.type in ['FileField', 'MultipleFileField'] %} {% elif field.type in ['FileField', 'MultipleFileField'] %}
{{ render_file_field(field, *args, **kwargs) }} {{ render_file_field(field, *args, **kwargs) }}
{% elif field.type in ['IntegerField', 'PasswordField', 'SelectField', 'StringField'] %} {% elif field.type in ['PasswordField', 'SelectField', 'StringField'] %}
{{ render_generic_field(field, *args, **kwargs) }} {{ render_generic_field(field, *args, **kwargs) }}
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
@ -39,14 +55,6 @@
{% endmacro %} {% endmacro %}
{% macro render_generic_field(field) %} {% macro render_generic_field(field) %}
{% if field.type == 'IntegerField' %}
{% set tmp = kwargs.update({'type': 'number'}) %}
{% if 'class_' in kwargs and 'validate' not in kwargs['class_'] %}
{% set tmp = kwargs.update({'class_': kwargs['class_'] + ' validate'}) %}
{% else %}
{% set tmp = kwargs.update({'class_': 'validate'}) %}
{% endif %}
{% endif %}
<div class="input-field"> <div class="input-field">
{% if 'material_icon' in kwargs %} {% if 'material_icon' in kwargs %}
<i class="material-icons prefix">{{ kwargs.pop('material_icon') }}</i> <i class="material-icons prefix">{{ kwargs.pop('material_icon') }}</i>