Add search results counter

This commit is contained in:
Jake Howard 2022-08-02 09:27:43 +01:00
parent 7647ace4a0
commit bcc9a2c2f2
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 18 additions and 0 deletions

10
static/src/js/search.js Normal file
View 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);
});

View file

@ -1,5 +1,7 @@
{% extends "wagtail_base.html" %} {% extends "wagtail_base.html" %}
{% load static %}
{% block content %} {% block content %}
{% include "common/hero.html" %} {% include "common/hero.html" %}
@ -33,8 +35,14 @@
</span> </span>
</p> </p>
</div> </div>
<p>Showing <span id="result-count">0</span> results</p>
</section> </section>
<section class="container" id="search-results"></section> <section class="container" id="search-results"></section>
{% endblock %} {% endblock %}
{% block extra_js %}
<script async defer type="text/javascript" src="{% static 'js/search.js' %}"></script>
{% endblock %}