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
|
||||
# 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(
|
||||
f"""SELECT * FROM suppliers s WHERE {where}
|
||||
ORDER BY
|
||||
|
||||
@@ -158,28 +158,27 @@
|
||||
</div>
|
||||
|
||||
<!-- 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..."
|
||||
class="dir-search"
|
||||
hx-get="{{ url_for('directory.results') }}"
|
||||
hx-trigger="input changed delay:300ms"
|
||||
hx-target="#dir-results"
|
||||
hx-include=".dir-search">
|
||||
<select name="country" class="dir-search"
|
||||
hx-include="#dir-search-form">
|
||||
<select name="country"
|
||||
hx-get="{{ url_for('directory.results') }}"
|
||||
hx-trigger="change"
|
||||
hx-target="#dir-results"
|
||||
hx-include=".dir-search">
|
||||
hx-include="#dir-search-form">
|
||||
<option value="">All Countries</option>
|
||||
{% 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>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select name="category" class="dir-search"
|
||||
<select name="category"
|
||||
hx-get="{{ url_for('directory.results') }}"
|
||||
hx-trigger="change"
|
||||
hx-target="#dir-results"
|
||||
hx-include=".dir-search">
|
||||
hx-include="#dir-search-form">
|
||||
<option value="">All Categories</option>
|
||||
{% for cat in category_counts %}
|
||||
<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