fix directory search: SQL param order and HTMX include selector
Parameter bindings for ORDER BY (now, country) were placed before WHERE params, causing mismatched bindings when any filter was active. Also switched hx-include from .dir-search class (shared by form + inputs) to #dir-search-form ID to prevent duplicate parameters. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -89,7 +89,7 @@ async def _build_directory_query(q, country, category, region, page, per_page=24
|
|||||||
|
|
||||||
offset = (page - 1) * per_page
|
offset = (page - 1) * per_page
|
||||||
# Tier-based ordering: sticky first, then pro > growth > free, then name
|
# Tier-based ordering: sticky first, then pro > growth > free, then name
|
||||||
order_params = [now, country or ""] + params + [per_page, offset]
|
order_params = params + [now, country or "", per_page, offset]
|
||||||
suppliers = await fetch_all(
|
suppliers = await fetch_all(
|
||||||
f"""SELECT * FROM suppliers s WHERE {where}
|
f"""SELECT * FROM suppliers s WHERE {where}
|
||||||
ORDER BY
|
ORDER BY
|
||||||
|
|||||||
@@ -158,28 +158,27 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Search + Filters -->
|
<!-- Search + Filters -->
|
||||||
<form method="get" class="dir-search">
|
<form method="get" class="dir-search" id="dir-search-form">
|
||||||
<input type="search" name="q" value="{{ q }}" placeholder="Search suppliers, countries, products..."
|
<input type="search" name="q" value="{{ q }}" placeholder="Search suppliers, countries, products..."
|
||||||
class="dir-search"
|
|
||||||
hx-get="{{ url_for('directory.results') }}"
|
hx-get="{{ url_for('directory.results') }}"
|
||||||
hx-trigger="input changed delay:300ms"
|
hx-trigger="input changed delay:300ms"
|
||||||
hx-target="#dir-results"
|
hx-target="#dir-results"
|
||||||
hx-include=".dir-search">
|
hx-include="#dir-search-form">
|
||||||
<select name="country" class="dir-search"
|
<select name="country"
|
||||||
hx-get="{{ url_for('directory.results') }}"
|
hx-get="{{ url_for('directory.results') }}"
|
||||||
hx-trigger="change"
|
hx-trigger="change"
|
||||||
hx-target="#dir-results"
|
hx-target="#dir-results"
|
||||||
hx-include=".dir-search">
|
hx-include="#dir-search-form">
|
||||||
<option value="">All Countries</option>
|
<option value="">All Countries</option>
|
||||||
{% for cc in country_counts %}
|
{% for cc in country_counts %}
|
||||||
<option value="{{ cc.country_code }}" {{ 'selected' if country == cc.country_code }}>{{ country_labels.get(cc.country_code, cc.country_code) }} ({{ cc.cnt }})</option>
|
<option value="{{ cc.country_code }}" {{ 'selected' if country == cc.country_code }}>{{ country_labels.get(cc.country_code, cc.country_code) }} ({{ cc.cnt }})</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
<select name="category" class="dir-search"
|
<select name="category"
|
||||||
hx-get="{{ url_for('directory.results') }}"
|
hx-get="{{ url_for('directory.results') }}"
|
||||||
hx-trigger="change"
|
hx-trigger="change"
|
||||||
hx-target="#dir-results"
|
hx-target="#dir-results"
|
||||||
hx-include=".dir-search">
|
hx-include="#dir-search-form">
|
||||||
<option value="">All Categories</option>
|
<option value="">All Categories</option>
|
||||||
{% for cat in category_counts %}
|
{% for cat in category_counts %}
|
||||||
<option value="{{ cat.category }}" {{ 'selected' if category == cat.category }}>{{ category_labels.get(cat.category, cat.category) }} ({{ cat.cnt }})</option>
|
<option value="{{ cat.category }}" {{ 'selected' if category == cat.category }}>{{ category_labels.get(cat.category, cat.category) }} ({{ cat.cnt }})</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user