Skip to content

draft: feat: playing around with filters #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 71 additions & 3 deletions app/views/another-decision-0-0-2/an-de-find-docs-alt1.html
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ <h1 class="govuk-heading-m govuk-!-margin-bottom-0">Filter document types</h1>
label: {
html: DynamicHeader
},
hint: {
text: ""
attributes: {
autocomplete: "off"
},
id: "find-document",
name: "find-document",
Expand All @@ -465,10 +465,78 @@ <h1 class="govuk-heading-m govuk-!-margin-bottom-0">Filter document types</h1>
<div class="govuk-button-group">
{{ govukButton({
text: "Apply filter",
classes: "govuk-button--secondary govuk-!-margin-bottom-8 govuk-!-margin-top-0"
attributes: {
id: "prototype-filter-search"
}
}) }}


{{ govukButton({
text: "Clear",
attributes: {
id: "prototype-filter-clear"
},
classes: "govuk-button--secondary " + ("govuk-visually-hidden" if not data["find-document"])
}) }}
<script>
const searchButton = document.getElementById("prototype-filter-search");
const clearButton = document.getElementById("prototype-filter-clear");

const searchBox = document.getElementById("find-document");
const checkboxes = document.querySelectorAll(".govuk-checkboxes__item");

const divider = document.querySelector(".govuk-checkboxes__divider");

const label = document.querySelector(".govuk-fieldset__heading");

function runSearch() {
const documents = {
found: 0,
hidden: 0,
}
checkboxes.forEach($item => {
const checkbox = $item.querySelector("input");
const label = $item.querySelector("label");
if (label.innerHTML.toLowerCase().includes(searchBox.value.toLowerCase()) || checkbox.checked === true || checkbox.value === "Advanced") {
$item.style.display = "block";
documents.found ++;
} else {
$item.style.display = "none";
documents.hidden ++;
}
})

if (documents.found === 1) {
divider.classList.add("govuk-visually-hidden");
label.innerHTML = `1 document found (${documents.hidden} hidden)`
} else {
divider.classList.remove("govuk-visually-hidden");
label.innerHTML = `${documents.found} document found ${documents.hidden === 0 ? "" : `(${documents.hidden} hidden)`}`;
}

if(documents.found) {}
}

clearButton.addEventListener("click", (e) => {
clearButton.classList.add("govuk-visually-hidden");
searchBox.value = "";
runSearch();
e.preventDefault();
});

searchButton.addEventListener("click", (e) => {
console.log("Attempting in browser filter");


runSearch();
if(searchBox.value.toLowerCase() !== "") {
clearButton.classList.remove("govuk-visually-hidden");
}

e.preventDefault();
});

</script>
</div>


Expand Down