Help with JS Function

We have created a DB with, amongst others, tables containing Country and Region data…
We have created the following function to filter the region Dataset based upon the CountryName selected from the Country DropDown…

This does not seem to work at all… any help would be appreciated

Thanks…

export function CountryDd_change(event, $w) { 
 //Add your code for this event here:  
 let myCountry = $w("#CountryDd").value; 
 console.log(myCountry); 
 $w("#RegionsDataset").setFilter(wixData.filter().contains("CountryName", myCountry));   

Hi Clive,

Collection fields usually start with a lowercase letter. Try changing ‘CountryName’ to ‘countryName’:

 $w("#RegionsDataset").setFilter(wixData.filter().contains("countryName", myCountry));

We changed the field names to ensure they started with a lowercase, and changed code to reflect this, still does not work

Laurence and I are working together BTW

Hi,
Is it possible that the name of the dataset element is dataset1 (default name) ?
If it still doesn’t work please share a link to your site and specify the name of the relevant page.
Roi

Make sure that you are using the Field Key ( not the Field Name). The Field Name is for human consumption only, the Field Key is used by Wix Code in queries.


As Roi pointed out, make sure that you are using the correct Dataset name.

Also, is the dataset connected to the collection?

Hi,

Thank you so much, it was the name of the field, talk about a schoolboy error:)