I have a search and some filters on a drupal 7 site. If I search a term, for example "stuff", and there are 30 results, I can click a checkbox filter (let's call it FilterA) on the side and narrow my results down. But now if I type "things" in the search bar and submit it, FilterA is still clicked when the results come up. I need for all the filters to be unchecked when I perform a new search. I've gone through I feel every setting in the view and all the search and filter settings and still nothing. Thank you for any help you can provide.
To fix this I created a new block and inserted this code:
<script>
//unchecks all checkboxes
function clearCheckBoxes(){
var uncheck=document.getElementsByTagName('input');
for(var i=0;i<uncheck.length;i++){
if(uncheck[i].type=='checkbox'){
uncheck[i].checked=false;
}
}
}
//this function makes sure that new searches aren't hindered by filters set for previous searches.
jQuery(function(){
if(typeof(Storage) !== "undefined"){
//retrieve what's in search box and remove whitespace
var currentsearch = document.getElementById("searchbar").value;
currentsearch = currentsearch.trim();
//if search box has a value that differs from the session storage search value then filter checkboxes are unchecked and url is sanitized of categories
if (currentsearch.length > 0){
if (sessionStorage.getItem("squery")) {
let oldsearch = sessionStorage.getItem("squery");
if(currentsearch !== oldsearch){
clearCheckBoxes();
location.pathname = 'simplepathname';
}
}
// set session storage search value equal to current value
sessionStorage.setItem("squery", currentsearch);
}
}
});
</script>