Finsweet part
Class : "list-test" hold the cms components
Class : "filtreprixall" hold the button who filter components
Custom part
The input field as the ID "myinput"
The button has the ID "divprixall"
If you want help and can explain why without this line Finsweet script crash tell me !!!!
$("#divprixall").click(function () {})
// Without this line Finesweet script crash.
//maybee Finsweet team could explain why.
<script src="https://cdn.finsweet.com/files/cmslibrary-v1.8.js"></script>
<script>
// immediately/self invoked function. This function executes right away
(function finsweeet() {
// create a new Library instance and store it in a variable called "fsComponent"
var fsComponent = new FsLibrary('.list-test') // Collection List class
// define filter groups in an array and store it in a variable called myFilters
var myFilters = [ {
filterWrapper: '.filtreprixall', // parent wrapper of filter group
filterType: 'exclusive',
filterByClass:".prixacheterfield",
filterRange: true
},
]
// run the filter Library component on your instance
fsComponent.filter({
filterArray: myFilters, // variable of the array we created above
activeClass: 'selectedtest', // class that styles the active state
})
})();// end of finesweet
$("#divprixall").click(function () {}) // I don't know why but it doesn't works without this
$( "#myinput" )
.keyup(function() {
var myvalue = $( this ).val(); // grab the value of the input
var longueur= myvalue.length; // get the length
if (longueur >0){ // if the field is not empty
$("#divprixall").trigger("click"); // trigger click
var prixmax= "0-"+myvalue; // create a filter range value
var inputprix = document.getElementById('divprixall'); // grab the button
inputprix.setAttribute('filter-by', prixmax ); // set the filter by new valus
$("#divprixall").trigger("click"); // trigger click
}else { // when the field is empty
$("#divprixall").trigger("click");// trigger click
var inputprix = document.getElementById('divprixall');// grab the button
inputprix.setAttribute('filter-by', '0-100000000000' ); // set the filter by to a super high value
$("#divprixall").trigger("click"); // trigger click
}; })
.keyup();
</script>