{% comment %} Grid Form Layout ================ Renders form fields in a responsive grid layout. Purpose: Provides a multi-column grid layout for forms with many fields. Responsive - adjusts columns based on screen size. Usage Examples: 2-column grid: {% include 'forms/layouts/grid.html' with form=form cols=2 %} 3-column grid: {% include 'forms/layouts/grid.html' with form=form cols=3 %} With full-width fields: {% include 'forms/layouts/grid.html' with form=form cols=2 full_width='description,notes' %} Parameters: Required: - form: Django form object Optional: - cols: Number of columns (2 or 3, default: 2) - exclude: Comma-separated field names to exclude - fields: Comma-separated field names to include - full_width: Comma-separated field names that span full width - show_help: Show help text (default: True) - show_required: Show required indicator (default: True) - gap: Grid gap class (default: 'gap-4') - submit_text: Submit button text (default: 'Submit') - submit_class: Submit button CSS class - form_class: Additional CSS classes for form wrapper Dependencies: - forms/partials/form_field.html - Tailwind CSS Accessibility: - Responsive grid maintains logical order - Labels properly associated with inputs {% endcomment %} {% load common_filters %} {% with show_help=show_help|default:True show_required=show_required|default:True cols=cols|default:2 gap=gap|default:'gap-4' submit_text=submit_text|default:'Submit' %}
{# Non-field errors #} {% if form.non_field_errors %} {% endif %} {# Grid container #}
{% for field in form %} {% if field.is_hidden %} {{ field }} {% elif fields %} {% if field.name in fields %}
{% include 'forms/partials/form_field.html' with field=field show_help=show_help required_indicator=show_required %}
{% endif %} {% elif exclude %} {% if field.name not in exclude %}
{% include 'forms/partials/form_field.html' with field=field show_help=show_help required_indicator=show_required %}
{% endif %} {% else %}
{% include 'forms/partials/form_field.html' with field=field show_help=show_help required_indicator=show_required %}
{% endif %} {% endfor %}
{# Form actions - full width #} {% if show_actions|default:True %}
{% if show_cancel and cancel_url %} {{ cancel_text|default:'Cancel' }} {% endif %}
{% endif %}
{% endwith %}