fix wtf macros

This commit is contained in:
Patrick Jentsch 2024-12-16 09:45:19 +01:00
parent cb53b27ebf
commit 16bf891654

View File

@ -7,6 +7,8 @@
{{ render_integer_field(field, *args, **kwargs) }} {{ render_integer_field(field, *args, **kwargs) }}
{% elif field.type == 'MultipleFileField' %} {% elif field.type == 'MultipleFileField' %}
{{ render_multiple_file_field(field, *args, **kwargs) }} {{ render_multiple_file_field(field, *args, **kwargs) }}
{% elif field.type == 'StringField' %}
{{ render_string_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 == 'TextAreaField' %} {% elif field.type == 'TextAreaField' %}
@ -20,7 +22,7 @@
{% macro render_boolean_field(field) %} {% macro render_boolean_field(field) %}
<div> <div>
<label> <label>
<input id="{{ field.id }}" name="{{ field.name }}" type="checkbox"> {{ field(*args, **kwargs) }}
<span>{{ field.label.text }}</span> <span>{{ field.label.text }}</span>
{% for error in field.errors %} {% for error in field.errors %}
<span class="helper-text error-color-text">{{ error }}</span> <span class="helper-text error-color-text">{{ error }}</span>
@ -36,25 +38,7 @@
<div class="file-field input-field"> <div class="file-field input-field">
<div class="btn"> <div class="btn">
<span>{{ field.label.text }}</span> <span>{{ field.label.text }}</span>
<input id="{{ field.id }}" name="{{ field.name }}" type="file"> {{ field(*args, **kwargs) }}
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="{{ placeholder }}">
</div>
{% for error in field.errors %}
<span class="helper-text error-color-text">{{ error }}</span>
{% endfor %}
</div>
{% endmacro %}
{% macro render_multiple_file_field(field) %}
{% set placeholder = kwargs.pop('placeholder', '') %}
<div class="file-field input-field">
<div class="btn">
<span>{{ field.label.text }}</span>
<input id="{{ field.id }}" name="{{ field.name }}" type="file" multiple>
</div> </div>
<div class="file-path-wrapper"> <div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="{{ placeholder }}"> <input class="file-path validate" type="text" placeholder="{{ placeholder }}">
@ -67,12 +51,29 @@
{% macro render_integer_field(field) %} {% macro render_integer_field(field) %}
<div class="input-field"> {% set classes = kwargs.pop('class_', '').split(' ') %}
{% if 'material_icon' in kwargs %}
<i class="material-icons prefix">{{ kwargs.pop('material_icon') }}</i> {% if 'validate' not in classes %}
{% set _ = classes.append('validate') %}
{% endif %} {% endif %}
<input class="validate" id="{{ field.id }}" name="{{ field.name }}" type="number">
<label for="{{ field.id }}">{{ field.label.text }}</label> {% set _ = kwargs.update({'class_': ' '.join(classes)}) %}
{{ render_generic_field(field, *args, **kwargs) }}
{% endmacro %}
{% macro render_multiple_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>
{% for error in field.errors %} {% for error in field.errors %}
<span class="helper-text error-color-text">{{ error }}</span> <span class="helper-text error-color-text">{{ error }}</span>
{% endfor %} {% endfor %}
@ -80,6 +81,19 @@
{% endmacro %} {% endmacro %}
{% macro render_string_field(field) %}
{% set classes = kwargs.pop('class_', '').split(' ') %}
{% if 'validate' not in classes %}
{% set _ = classes.append('validate') %}
{% endif %}
{% set _ = kwargs.update({'class_': ' '.join(classes)}) %}
{{ render_generic_field(field, *args, **kwargs) }}
{% endmacro %}
{% macro render_submit_field(field) %} {% macro render_submit_field(field) %}
<button class="btn waves-effect waves-light" id="{{ field.id }}" name="{{ field.name }}" type="submit"> <button class="btn waves-effect waves-light" id="{{ field.id }}" name="{{ field.name }}" type="submit">
{{ field.label.text }} {{ field.label.text }}
@ -91,26 +105,23 @@
{% macro render_text_area_field(field) %} {% macro render_text_area_field(field) %}
<div class="input-field"> {% set classes = kwargs.pop('class_', '').split(' ') %}
{% if 'material_icon' in kwargs %}
<i class="material-icons prefix">{{ kwargs.pop('material_icon') }}</i> {% if 'materialize-textarea' not in classes %}
{% set _ = classes.append('materialize-textarea') %}
{% endif %} {% endif %}
<textarea class="materialize-textarea validate" id="{{ field.id }}" name="{{ field.name }}"></textarea>
<label for="{{ field.id }}">{{ field.label.text }}</label> {% if 'validate' not in classes %}
{% for error in field.errors %} {% set _ = classes.append('validate') %}
<span class="helper-text error-color-text">{{ error }}</span> {% endif %}
{% endfor %}
</div> {% set _ = kwargs.update({'class_': ' '.join(classes)}) %}
{{ render_generic_field(field, *args, **kwargs) }}
{% endmacro %} {% endmacro %}
{% macro render_generic_field(field) %} {% macro render_generic_field(field) %}
{% set classes_ = kwargs.pop('class_', '').split(' ') %}
{% if 'validate' not in classes_ %}
{% set _ = classes_.append('validate') %}
{% endif %}
{% set _ = kwargs.update({'class_': ' '.join(classes_)}) %}
<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>