{#- SPDX-License-Identifier: Apache-2.0 SPDX-FileCopyrightText: 2025 - 2026 BMO Soluciones, S.A. -#} {# Form rendering macros #} {% macro render_field(field, class="form-control", disabled=False) %}
{% if field.type == 'BooleanField' %} {# Checkbox with Bootstrap 5 form-check structure #}
{{ field(class="form-check-input" + (" is-invalid" if field.errors else ""), disabled=disabled) }} {{ field.label(class="form-check-label") }} {% if field.errors %} {% for error in field.errors %}
{{ error }}
{% endfor %} {% endif %}
{% elif field.type == 'RadioField' %} {# Radio buttons with Bootstrap 5 form-check structure #} {{ field.label(class="form-label") }} {% for subfield in field %}
{{ subfield(class="form-check-input" + (" is-invalid" if field.errors else ""), disabled=disabled) }} {{ subfield.label(class="form-check-label") }}
{% endfor %} {% if field.errors %} {% for error in field.errors %}
{{ error }}
{% endfor %} {% endif %} {% elif field.type == 'SelectField' or field.type == 'SelectMultipleField' %} {# Select dropdowns with Bootstrap 5 form-select #} {{ field.label(class="form-label") }} {{ field(class="form-select" + (" is-invalid" if field.errors else ""), disabled=disabled) }} {% if field.errors %} {% for error in field.errors %}
{{ error }}
{% endfor %} {% endif %} {% else %} {# Standard inputs (text, email, password, number, date, etc.) with form-control #} {{ field.label(class="form-label") }} {{ field(class="form-control" + (" is-invalid" if field.errors else ""), disabled=disabled) }} {% if field.errors %} {% for error in field.errors %}
{{ error }}
{% endfor %} {% endif %} {% endif %}
{% endmacro %} {% macro render_messages() %} {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} {% for category, message in messages %} {% endfor %} {% endif %} {% endwith %} {% endmacro %} {% macro render_form_errors(form) %} {% if form.errors %} {% endif %} {% endmacro %} {% macro render_pagination(pagination, endpoint) %} {% if pagination.pages > 1 %} {# Create a dict of query args excluding 'page' to avoid duplicate keyword argument #} {% set query_args = request.args.to_dict(flat=False) %} {% if query_args.pop('page', None) %}{% endif %} {% endif %} {% endmacro %}