Dear community
I’ve created a “property search” using dropdowns working fine, but since i add another filter named “balcony” using checkbox" (#checkbox1) when i run the script, i have always “NO RESULTS” unless i check my checkbox, so i got results with balcony, but if i don’t “check” my box : NO RESULTS. here is my code :
import {wixData} from 'wix-data';
export function button1_click(event, $w) {
$w("#dataset1").setFilter(wixData.filter()
.contains("nomDuBien", $w('#dropdown5') .value)
.ge("pieces", $w('#dropdown2') .value)
.eq("balcon", $w('#checkbox1').checked)
.between("surface",parseFloat($w('#dropdown6').value), parseFloat($w('#dropdown7').value))
.between("price",parseFloat($w('#dropdown3').value), parseFloat($w('#dropdown4').value)))
.then((results) => {
if ($w("#dataset1").getTotalCount() > 0) {
$w("#repeater1").expand();
$w("#text80").text = "Voici vos résultats";
$w("#repeater1").data = results.items;
} else {
$w("#repeater1").collapse();
$w("#text80").text = "Désolé il n'y a pas de résultats, essayez d'autres critères";
}
}).catch((err) => {
console.log(err);
});
}
I need to understand how to get results even if the (#checkbox1) is not checked, i still got my results. Thx to all…
Your filter:
.eq("balcon", $w('#checkbox1').checked)
inspects the value of the balcon field.
If the balcon field is true, then it’s successful. But what happens if the field is not true. Is the field set to false, or is it undefined? If the balcon field is undefined, that means it’s not equal to false (and of course it’s not equal to true either).
Also, if the case when #checkbox1 is not checked means that you don’t want to apply a balcony filter, then you need to ignore this filter.
You can build your filter [something] like this:
let filter = wixData.filter()
.contains("nomDuBien", $w('#dropdown5') .value)
.ge("pieces", $w('#dropdown2') .value)
.between("surface",parseFloat($w('#dropdown6').value),parseFloat($w('#dropdown7').value))
.between("price",parseFloat($w('#dropdown3').value),parseFloat($w('#dropdown4').value));
// see if we want to add the balcony filter
if($w('#checkbox1').checked === true) {
filter = filter.eq("balcon", true);
}
$w("#dataset1").setFilter(filter);
Note: this has not been tested. It merely illustrates how you can conditionally include certain conditions to a filter.
Thanks again @yisrael-wix but it doesn’t work, i always have error on the code by putting
let filter = wixData.filter()
Wherever i place this between “export function” and “.then”
import {wixData} from 'wix-data';
export function button1_click(event, $w) {
$w("#dataset1").setFilter(wixData.filter()
.contains("nomDuBien", $w('#dropdown5') .value)
.ge("pieces", $w('#dropdown2') .value)
.eq("balcon", $w('#checkbox1').checked)
.between("surface",parseFloat($w('#dropdown6').value), parseFloat($w('#dropdown7').value))
.between("price",parseFloat($w('#dropdown3').value), parseFloat($w('#dropdown4').value)))
.then((results) => {
if ($w("#dataset1").getTotalCount() > 0) {
$w("#repeater1").expand();
$w("#text80").text = "Voici vos résultats";
$w("#repeater1").data = results.items;
} else {
$w("#repeater1").collapse();
$w("#text80").text = "Désolé il n'y a pas de résultats, essayez d'autres critères";
}
}).catch((err) => {
console.log(err);
});
}
This code below is working smoothly thanks to @yisrael-wix ! i even created another checkbox “#checkbox2” for sea view… ans i can add as many filter as i want now ! thanks again…
let filter = wixData.filter()
.contains("nomDuBien", $w('#dropdown5') .value)
.ge("pieces", $w('#dropdown2') .value)
.between("surface",parseFloat($w('#dropdown6').value), parseFloat($w('#dropdown7').value))
.between("price",parseFloat($w('#dropdown3').value), parseFloat($w('#dropdown4').value))
if($w('#checkbox1').checked === true) {
filter = filter.eq("balcon", true);
}
if($w('#checkbox2').checked === true) {
filter = filter.eq("vuemer", true);
}
$w("#dataset1").setFilter(filter)
Hey, I’m so you glad you got this working. I was just setting up a test to see what caused the problem, and then I see you got it working. 

@yisrael-wix Beacuse i did it wrong the first time… may i ask you an extra cherry on the cake ?
I Display alrerady a message saying if there’s results or not :
then((results) => {
if ($w("#dataset1").getTotalCount() > 0) {
$w("#repeater1").expand();
$w("#text80").text = "Voici vos résultats";
$w("#repeater1").data = results.items;
} else {
$w("#repeater1").collapse();
$w("#text80").text = "Désolé il n'y a pas de résultats, essayez d'autres critères";
}
}).catch((err) => {
console.log(err);
});
}
I would love to display also the number of items in case of results…
@fizzfantasy Well, something like this would add the number of items to the end of your message.
$w("#text80").text = "Voici vos résultats: " + results.items.length + " éléments";
Umm, don’t laugh at me since I don’t know French. Just create whatever text you want using the length of the returned array of items.
@yisrael-wix can’t laugh at you since the help you gave me !!! for info, voici les résultats = here’s your results.
So chief…I tried to add after “voici vos résultats:”
+ results.items.length + " éléments";
But now nothing’s moving… my texte does not change…
@fizzfantasy Hmmm…
Let me take a look. Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.
@fizzfantasy
Your repeater is connected to a dataset, so you don’t need this line:
$w("#repeater1").data = results.items;
When you set the dataset’s filter, the contents of the Repeater change automatically since the repeater is connected to the dataset. Sorry I didn’t catch this earlier.
Use this instead. The repeater should display the correct repeater contents and display the message with the number of items returned from the filter.
$w("#dataset1").setFilter(filter)
.then(() => {
if ($w("#dataset1").getTotalCount() > 0) {
$w("#repeater1").expand();
$w("#text80").text = "Voici vos résultats " + $w("#dataset1").getTotalCount() + " éléments";
} else {
$w("#repeater1").collapse();
$w("#text80").text = "Désolé il n'y a pas de résultats, essayez d'autres critères";
}
}).catch((err) => {
console.log(err);
});