27 lines
No EOL
1.2 KiB
HTML
27 lines
No EOL
1.2 KiB
HTML
{% comment %}
|
|
This fragment renders a friend code selector used for filtering or form submissions.
|
|
Expected variables:
|
|
- friend_codes: A list or QuerySet of FriendCode objects.
|
|
- selected_friend_code: The currently selected FriendCode.
|
|
- field_name (optional): The name/id for the input element (default "friend_code").
|
|
- label (optional): The label text (default "Friend Code").
|
|
{% endcomment %}
|
|
|
|
{% with field_name=field_name|default:"friend_code" label=label|default:"Friend Code" %}
|
|
{% if friend_codes|length > 1 %}
|
|
<div class="form-control">
|
|
<label for="{{ field_name }}" class="label">
|
|
<span class="label-text p-2 rounded">{{ label }}</span>
|
|
</label>
|
|
<select id="{{ field_name }}" name="{{ field_name }}" class="select select-bordered w-full bg-secondary text-white">
|
|
{% for code in friend_codes %}
|
|
<option value="{{ code.pk }}" {% if code.pk|stringformat:"s" == selected_friend_code.pk|stringformat:"s" %}selected{% endif %}>
|
|
{{ code.friend_code }}
|
|
</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
{% else %}
|
|
<input type="hidden" name="{{ field_name }}" value="{{ friend_codes.0.pk }}">
|
|
{% endif %}
|
|
{% endwith %} |