{# Shared form fields partial. Context: fields, errors, old, resource, prefix, resource_key, record_id (optional) #} {% macro render_field(field, old={}, errors={}, record=none) %} {% set val = old.get(field.attribute, '') %} {% set has_error = field.attribute in errors %} {% if field.field_type == 'boolean' %}
{{ field.label }}
{% if field._help_text %}

{{ field._help_text }}

{% endif %} {% if has_error %}

{{ errors[field.attribute][0] }}

{% endif %}
{% elif field.field_type == 'select' %}
{% if field._help_text %}

{{ field._help_text }}

{% endif %} {% if has_error %}

{{ errors[field.attribute][0] }}

{% endif %}
{% elif field.field_type == 'image' %}
{% set img_url = field.url_for(record) if record is not none else none %} {% if img_url %}
{{ field.label }}

Current image. Upload a new file to replace it.

{% endif %}
{% if field._help_text %}

{{ field._help_text }}

{% endif %} {% if has_error %}

{{ errors[field.attribute][0] }}

{% endif %}
{% elif field.field_type == 'richtext' %}
{% if field._help_text %}

{{ field._help_text }}

{% endif %} {% if has_error %}

{{ errors[field.attribute][0] }}

{% endif %}
{% elif field.field_type == 'textarea' %}
{% if field._help_text %}

{{ field._help_text }}

{% endif %} {% if has_error %}

{{ errors[field.attribute][0] }}

{% endif %}
{% elif field.field_type == 'password' %}
{% if has_error %} {% endif %}
{% if field._help_text %}

{{ field._help_text }}

{% endif %} {% if has_error %}

{{ errors[field.attribute][0] }}

{% endif %}
{% elif field.field_type in ('datetime', 'date') %}
{% if field._help_text %}

{{ field._help_text }}

{% endif %} {% if has_error %}

{{ errors[field.attribute][0] }}

{% endif %}
{% elif field.field_type == 'number' or field.field_type == 'currency' %}
{% if field._help_text %}

{{ field._help_text }}

{% endif %} {% if has_error %}

{{ errors[field.attribute][0] }}

{% endif %}
{% elif field.field_type == 'belongs_to' %}
{% if field._searchable %} {# Autocomplete: text input for display, hidden input for actual FK value #}
{% else %} {# Select: loads all related records (suitable for smaller tables) #}
{% endif %}
{% if field._help_text %}

{{ field._help_text }}

{% endif %} {% if has_error %}

{{ errors[field.attribute][0] }}

{% endif %}
{% else %} {# text, email, slug, badge default #}
{% if has_error %} {% endif %}
{% if field._help_text %}

{{ field._help_text }}

{% endif %} {% if has_error %}

{{ errors[field.attribute][0] }}

{% endif %}
{% endif %} {% endmacro %}