{% if field.get_model() %} {# ── Model-based relationship combobox ──────────────────────────────────────── Queries the model directly via the panel's GET /_model_search endpoint. The nuruCombobox Alpine component is registered in layout.html's alpine:init listener — nothing extra is needed here. Field attrs: field.model — SQLModel class (provides the model name in the URL) field.value_field — attr used as FK value (default: 'id') field.label_field — attr shown as label (default: str(record)) field.relationship — attr on *this* record for detail-view display only Context variables (injected by macros/form_item.html): current — current FK value (int / str / None) has_error — bool errors — dict { field_key: message } input_class — pre-built Tailwind input classes panel_prefix — URL prefix of this admin panel #} {% set _vf = field.get_value_field() or 'id' %} {% set _lf = field.get_label_field() or '' %} {% set _search_url = panel_prefix ~ '/_model_search?model=' ~ field.get_model().__name__ ~ '&value_field=' ~ _vf ~ ('&label_field=' ~ _lf if _lf else '') %}
{# Hidden input carries the FK value on form submit #}
{# Loading skeleton — shown only during the initial fetch #}
{# Search input + clear button #}
{# Spinner shown during remote fetches (not the initial load) #}
{# Dropdown — teleported to to escape any overflow:hidden ancestor. @mousedown.prevent on options keeps focus on the text input (preventing @blur from firing before pick() runs). #}
{% if has_error %}

{{ errors[field.get_key()] }}

{% elif field.get_help_text() %}

{{ field.get_help_text() }}

{% endif %}
{% else %} {# If `native=True` render a plain {% if not field.is_multiple() %}{% endif %} {% for opt in field.get_options() %} {% set opt_value = opt.value if opt is mapping else opt %} {% set opt_label = opt.label if opt is mapping else opt %} {% set is_selected = (current == opt_value) if not field.is_multiple() else (opt_value in current) %} {% endfor %} {% if has_error %}

{{ errors[field.get_key()] }}

{% elif field.get_help_text() %}

{{ field.get_help_text() }}

{% endif %} {% else %} {# Combobox for static/options array source #} {% set _opts = field.get_options() or [] %}
{# Hidden input carries the value on form submit #}
{% if has_error %}

{{ errors[field.get_key()] }}

{% elif field.get_help_text() %}

{{ field.get_help_text() }}

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