Add search results counter
This commit is contained in:
parent
7647ace4a0
commit
bcc9a2c2f2
2 changed files with 18 additions and 0 deletions
10
static/src/js/search.js
Normal file
10
static/src/js/search.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
window.addEventListener("load", () => {
|
||||
const searchResults = document.getElementById("search-results");
|
||||
const resultsCount = document.getElementById("result-count");
|
||||
|
||||
function handleSearchResults(event) {
|
||||
resultsCount.textContent =
|
||||
event.target.querySelectorAll(".listing-item").length;
|
||||
}
|
||||
searchResults.addEventListener("htmx:after-swap", handleSearchResults);
|
||||
});
|
|
@ -1,5 +1,7 @@
|
|||
{% extends "wagtail_base.html" %}
|
||||
|
||||
{% load static %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% include "common/hero.html" %}
|
||||
|
@ -33,8 +35,14 @@
|
|||
</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p>Showing <span id="result-count">0</span> results</p>
|
||||
</section>
|
||||
|
||||
<section class="container" id="search-results"></section>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script async defer type="text/javascript" src="{% static 'js/search.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue