Multiple custom filter with switches on a dataset.

Hey guys!

I’ve been cracking my skull over this problem for the last three days.


This is part of my filter page.

My webpage offers the customers to find musicians from a filter based on the category of the musician. The filter can have many values contained that all exist within the same field.

  • The switches value is set so that each one is different.

  • Pressing the “Vista” button will search for the filter.

  • Pressing the “Hreinsa” button will erase the filter.

  • The text above the repeater shows results based on the items found.
    What’s the problem you ask?


  1. I can’t seem to be able to assign the value of the switch to the filter.

  2. When I press “Hreinsa”(Clear) I would like the switches to revert back to off.
    Here is my code:

import wixData from 'wix-data';

$w.onReady(() => {
        //the dataset is primed at the beginning. It's connected to a repeater.
    $w('#dataset2').onReady(() => {
        count();
        //This are the search buttons for the filter, they work properly from what I can see.
    $w('#vista').onClick(() => {
        search();
      })
    $w('#vista2').onClick(() => {
        search();
      })
      //Here is the working clear filter. I'd like to add here a reset to the switches positions.
       $w('#hreinsa').onClick(() => {
        $w('#weddingswitch').value = "false";
        $w('#dataset2').setFilter(wixData.filter())
          .then(count);
        });
        
//Here comes the part that I'm having trouble assigning the value to the filter correctly
function search() {
 let filter = wixData.filter();
 let wedding = $w("#weddingswitch").value;
 if ($w('#weddingswitch').checked) {
    filter = filter.eq("flokkur", wedding);
}
$w('#dataset2').setFilter(filter)
    .then(count);
    }
    //the count works no prob
function count() {
 let total = $w('#dataset2').getTotalCount();
 if (total > 0) {
    $w('#textCount').text = `${total} Tónlistarmenn.`;
        } else {
        $w('#textCount').text = "Það er enginn sem uppfyllir þessar kröfur!";
        }
    }
 
});
});

All help is appreciated.

It seems like I managed to solve the first problem on my own! Eureka! The only thing that was wrong was that I assigned the filter to be equal to the value. I changed it so that it now contains the value and it worked!

Only problem 2 left.