Hello,
I have this error that appears when I want to run the code to see if it works.
Because I would like to know if it will display me the results randomly at each submission.
And here is the name of the collection: Liste praticiens
And its id : Listepraticiens
And here is the code that I have and it doesn’t show me any error:
import wixData from 'wix-data';
$w.onReady(function () {
$w("#dropdownreg, #dropdowndep").onChange(function () {
search();
});
});
dropdownreg();
//SEARCH BUTTON TRIGGER⚡
$w("#searchButton2").onClick(function () {
search();
});
function dropdownreg() {
wixData.query("#Listepraticiens")
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w("#dropdownreg").options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.region);
return [...new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return { label: curr, value: curr };
});
}
}
export function dropdownreg_change(event, $w) {
dropdowndep();
$w("#dropdowndep").enable();
locationCityFilter();
}
function locationCityFilter() {
$w("#dataPraticien").setFilter(wixData.filter()
.eq("region", $w("#dropdownreg").value)
);
}
function dropdowndep() {
wixData.query("#Listepraticiens")
.contains("departement", $w("#dropdownreg").value)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w("#dropdowndep").options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.departement);
return [...new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return { label: curr, value: curr };
});
}
}
function search() {
const query = wixData.query("#Listepraticiens")
.contains('departement', String($w('#dropdowndep').value))
.and(wixData.filter().eq("region", String($w('#dropdownreg').value)))
.ascending("_random"); // ajout de l'ordre aléatoire
$w("#dataPraticien").onReady(() => {
$w("#dataPraticien").setFilter(query)
.then(count)
});
//CLEAR FILTER 🚀
$w("#button31").onClick(function () {
$w("#dropdowndep").value = undefined;
$w("#dropdownreg").value = undefined;
$w("#dataPraticien").setFilter(wixData.filter());
$w('#nbrpraticiens').hide();
});
//COUNT FUNCTION👍
function count() {
let total = $w('#dataPraticien').getTotalCount();
if (total > 1) {
$w('#nbrpraticiens').text = `${total} praticiens trouvés`;
$w('#nbrpraticiens').show();
}
if (total === 1) {
$w('#nbrpraticiens').text = `${total} praticien trouvé`;
$w('#nbrpraticiens').show();
}
if (total === 0) {
$w('#nbrpraticiens').text = "Nous n'avons pas encore de praticien dans ce secteur";
$w('#nbrpraticiens').show();
}
//SCROLL TO THE TOP WHEN PAGINATION IS CHANGED ⚡
$w("#pagination1").onChange(() => {
$w("#haut").scrollTo();
});
}
}
Thanks in advance.