Files
TimeTracker/app/templates/components/client_select.html
T
Dries Peeters 5949670c65 fix(time-entries): improve user filter and stop auto-adding client filter
- Fix user dropdown selection: use explicit type-safe comparison
  (filters.user_id|string == user.id|string) so the correct user
  stays selected after pagination or page reload
- Exclude client_id from filter URL when it is auto-selected
  (single client or locked client): add data-auto-client attribute
  to client_select hidden inputs and skip them in getFilterParams
  so filtering by user alone no longer forces client_id=1 into the URL

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-05 20:54:39 +01:00

27 lines
2.0 KiB
HTML

{# Client select component - when only one client exists, pre-fill and gray out per Issue #467 #}
{% macro client_select(name, clients, selected_id=None, required=False, only_one_client=False, single_client=None, id=None) %}
{% set input_id = id or name %}
{% set locked_client = get_locked_client() %}
{% if locked_client %}
<input type="hidden" name="{{ name }}" id="{{ input_id }}" value="{{ locked_client.id }}" data-auto-client="true">
<input type="text" class="form-input bg-gray-100 dark:bg-gray-700 cursor-not-allowed opacity-75"
value="{{ locked_client.name }}" disabled readonly aria-label="{{ _('Client (auto-selected)') }}">
{% elif (not only_one_client) and (single_client is none) and clients and (clients|length == 1) %}
{# Fallback: if route didn't pass only_one_client/single_client, infer it from the list #}
<input type="hidden" name="{{ name }}" id="{{ input_id }}" value="{{ clients[0].id }}" data-auto-client="true">
<input type="text" class="form-input bg-gray-100 dark:bg-gray-700 cursor-not-allowed opacity-75"
value="{{ clients[0].name }}" disabled readonly aria-label="{{ _('Client (auto-selected)') }}">
{% elif only_one_client and single_client %}
<input type="hidden" name="{{ name }}" id="{{ input_id }}" value="{{ single_client.id }}" data-auto-client="true">
<input type="text" class="form-input bg-gray-100 dark:bg-gray-700 cursor-not-allowed opacity-75"
value="{{ single_client.name }}" disabled readonly aria-label="{{ _('Client (auto-selected)') }}">
{% else %}
<select name="{{ name }}" id="{{ input_id }}" class="form-input" {% if required %}required{% endif %}>
<option value="">{% if required %}{{ _('Select a client...') }}{% else %}{{ _('Select a client (optional)') }}{% endif %}</option>
{% for client in clients %}
<option value="{{ client.id }}" {% if selected_id is not none and selected_id|string == client.id|string %}selected{% endif %}>{{ client.name }}</option>
{% endfor %}
</select>
{% endif %}
{% endmacro %}