nopaque/web/app/templates/macros/materialize.html.j2

87 lines
3.0 KiB
Plaintext
Raw Normal View History

2020-04-17 09:13:11 +00:00
{% macro render_field(field) %}
{% if field.flags.required and field.type not in ['FileField', 'MultipleFileField'] %}
{% 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 %}
2020-04-17 09:04:09 +00:00
{% if field.type == 'BooleanField' %}
2020-04-17 09:13:11 +00:00
{{ render_boolean_field(field, *args, **kwargs) }}
{% elif field.type == 'DecimalRangeField' %}
{{ render_decimal_range_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) }}
2020-04-17 09:04:09 +00:00
{% elif field.type == 'SubmitField' %}
2020-04-17 09:13:11 +00:00
{{ render_submit_field(field, *args, **kwargs) }}
2020-04-17 09:04:09 +00:00
{% elif field.type in ['FileField', 'MultipleFileField'] %}
2020-04-17 09:13:11 +00:00
{{ render_file_field(field, *args, **kwargs) }}
{% elif field.type in ['PasswordField', 'SelectField', 'StringField'] %}
2020-04-17 09:13:11 +00:00
{{ render_generic_field(field, *args, **kwargs) }}
2020-04-17 09:04:09 +00:00
{% endif %}
{% endmacro %}
2020-04-17 09:13:11 +00:00
{% macro render_boolean_field(field) %}
{% set label = kwargs.pop('label', True) %}
<div class="switch">
{% if 'material_icon' in kwargs %}
<i class="material-icons prefix">{{ kwargs.pop('material_icon') }}</i>
{% endif %}
<label>
{% if label %}
{{ field.label.text }}
{% endif %}
{{ field(*args, **kwargs) }}
<span class="lever"></span>
</label>
{% for error in field.errors %}
<span class="helper-text red-text">{{ error }}</span>
{% endfor %}
</div>
2020-04-17 09:04:09 +00:00
{% endmacro %}
2020-04-17 09:13:11 +00:00
{% macro render_file_field(field) %}
{% set placeholder = kwargs.pop('placeholder', '') %}
<div class="file-field input-field">
<div class="btn">
<span>{{ field.label.text }}</span>
{{ field(*args, **kwargs) }}
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="{{ placeholder }}">
</div>
2020-04-17 09:04:09 +00:00
</div>
{% endmacro %}
2020-04-17 09:13:11 +00:00
{% macro render_generic_field(field) %}
{% set label = kwargs.pop('label', True) %}
2020-04-17 09:04:09 +00:00
<div class="input-field">
{% if 'material_icon' in kwargs %}
<i class="material-icons prefix">{{ kwargs.pop('material_icon') }}</i>
{% endif %}
{{ field(*args, **kwargs) }}
{% if label %}
2020-04-17 09:04:09 +00:00
{{ field.label }}
{% endif %}
2020-04-17 09:04:09 +00:00
{% for error in field.errors %}
<span class="helper-text red-text">{{ error }}</span>
{% endfor %}
</div>
{% endmacro %}
2020-04-17 09:13:11 +00:00
{% macro render_submit_field(field) %}
<button class="btn waves-effect waves-light" id="{{ field.id }}" name="{{ field.name }}" type="submit" value="{{ field.label.text }}">
{{ field.label.text }}
{% if 'material_icon' in kwargs %}
<i class="material-icons right">{{ kwargs.pop('material_icon') }}</i>
{% endif %}
</button>
2020-04-17 09:04:09 +00:00
{% endmacro %}