From f17bebac3ccaaa755a86a9dd27dee2c1d84f5d2d Mon Sep 17 00:00:00 2001
From: Struan Donald <struan@exo.org.uk>
Date: Mon, 23 Oct 2023 15:50:25 +0100
Subject: [PATCH] [scorecards] fix the show specific council section page
 dropdown

Fixes #594
---
 scoring/static/scoring/js/main.js      | 21 +++++++++++++++++++++
 scoring/templates/scoring/section.html |  2 +-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/scoring/static/scoring/js/main.js b/scoring/static/scoring/js/main.js
index e21ff63c..58e187cc 100644
--- a/scoring/static/scoring/js/main.js
+++ b/scoring/static/scoring/js/main.js
@@ -341,6 +341,27 @@ forEachElement('.js-methodology-council-autocomplete', function(input){
     });
 });
 
+forEachElement('.js-section-council-autocomplete', function(input){
+    var ac = new Awesomplete(
+        input,
+        {
+            list: councils.map(function(council){
+                return council.name;
+            }),
+            minChars: 3,
+            autoFirst: true
+        }
+    );
+    input.parentNode.addEventListener('awesomplete-selectcomplete', function(data){
+        var council = findItem(councils, {'name': data.text });
+        var sp = new URLSearchParams(window.location.search)
+        sp.delete('type');
+        sp.delete('council');
+        sp.append('council', council.slug);
+        window.location.href = window.location.pathname + '?' + sp.toString() + '#questions';
+    });
+});
+
 function ajaxLoadCouncilTypeScorecard(url) {
     var selectors = [
         '#council-type-filter',
diff --git a/scoring/templates/scoring/section.html b/scoring/templates/scoring/section.html
index 0ecdb524..b470776b 100644
--- a/scoring/templates/scoring/section.html
+++ b/scoring/templates/scoring/section.html
@@ -138,7 +138,7 @@ <h3 class="mb-4" id="questions">Questions in this section</h3>
         <div class="col-lg-6">
             <div class="bg-primary-100 p-3 mb-4 border rounded">
                 <label for="questions-council-name" class="d-block mb-2">Show questions for a specific council</label>
-                <input class="form-control searchbar js-methodology-council-autocomplete" type="search" placeholder="Council name" aria-label="Council name" id="questions-council-name">
+                <input class="form-control searchbar js-section-council-autocomplete" type="search" placeholder="Council name" aria-label="Council name" id="questions-council-name">
                 <p class="mt-3 mt-lg-4 mb-2">Or show questions by type of council</p>
                 <div class="d-flex flex-wrap gap-1">
                     <a href="{% url 'scoring:section' section.code %}?type=single#questions" class="btn btn-outline-primary btn-sm is--with-label" data-methodology-switch-council-type="single" data-bs-toggle="tooltip" data-bs-placement="top"