Your problem is, that you are mixing Wix-Data with DATASET-Code-Parts.
It is the most common issue you will find here inside the Velo-Forum.
Everyone who tries to mix wix-data with datasets → end in NOWHERE with a lot of issues —> LIKE YOU NOW <—.
Also your code-structure is very CHAOTIC.
And if i take a look onto those code-parts…
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 };
});
}
…it feels like it is my own code. Where did you get it from ?
I also did not see this code-part in your very first post (which you have deleted or updated).
Ok, back to your problem:
You also do not use ASYNC-AWAIT or .then()-method the right way.
You do not place functions onto the right place in your code.
You do not give the right names for your functions, which can cause → CONFUSIONS.
If i would take some more time onto your code. surely i would find even more mistakes and strange code-parts.
Sooooo, let’s do it the right way, like it should be…
Your code ----> ALWAYS <— should start with…
$w.onReady(()=> { ... });
I think you will agree with me, because this part of code you did well.
But already the next CHECK-POINT you did not well ! What do i mean?
When you are starting your SERACH-ENGINE, by changing one of your 2-dropdowns, your Search-Function → starts a further function → “locationCityFilter()”.
Inside of this function you are working with a —> DATASET <—.
WHAT??? YOU ARE ALREADY WORKING WITH A DATASET, WITHOUT HAVE NEVER WAITING THE DATASET TO BE READY ???
Ok, let’s do it the right way…
So our last codeposition was —> $w.onReady()
And the very next code-line we want to have should be???
EXACTLY —> We want to wait our dataset first to be ready , before we start to work with it…
$w.onReady(()=> {
$w('#dataPraticien').onReady(()=>{
});
});
Huray, first of your issues → resolved!
What next?
Oh yeah, you have some Dropdowns i forgot…
and also i forgot to mention that the very first code-line of your page code of course should be an IMPORT, if you are using some API-Functions…
import wixData from 'wix-data';
$w.onReady(()=> {
$w('#dataPraticien').onReady(()=>{
$w("#dropdownreg").onChange(async()=>{
let dropdownregValue = $w("#dropdownreg").value;
let resultReg = await search(dropdownregValue);
console.log(resultReg);
});
$w("#dropdowndep").onChange(async()=>{
let dropdowndepValue = $w("#dropdowndep").value;
let resultDep = await search(dropdowndepValue);
console.log(resultDep);
});
xxxxx();
});
});
Huray! Your new CODE!
But what the hell is that?
AWAIT ? And what is this —> xxxxx. What the hell are you programming man?![]()
And there is even an ASYNC, what is that for?
Take a look onto which IDs and names you used inside your code…
$w("#dropdownreg, #dropdowndep").onChange(function(){........
export function dropdownreg_change(event, $w){..........
function dropdownreg(){wixData.query("#dataPraticien").....
-
It seems like everything inside your code is —> dropdownreg <—
You are using that for dropdowns, functions and export functions.
Surely not the best practise! -
You have splitted your dropdown-event onto two different code-parts.
-inside your onReady-Code-block and in an export-function.
Surely not the best practise!
How to name your used elements the best way?
If you use a dropdown → ddn + elementname —> “ddnReg” / “ddnDep”
If if would be an input-element —> inpReg / inpDep
If it would be a box -------> boxReg / boxDep
and so on…
Use logical element-IDs to be able to read your code easier and faster.
How to name your functions?
Use a name for your function which will describe functions functionality.
What does do → dropdownreg? (wait! wasn’t it a dropdown?)
Or no wait, it is a function… (you already understand what i mean?)
function dropdownreg() {
wixData.query("#dataPraticien")
.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 };
});
}
}
So one more time → Which name should this function have???
My suggestion would be —> “get_DataPraticien”. This would be a GOOD name for this function, but surely not —> “dropdownreg”.