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" %}
{% 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 %}