I have just recently starting building my website and am looking for how to combine my code. What I have is a database with location tags (by state) and tags for what each location offers). I currently have the code working, however, when I drop down by location, it gives me the state with the correct result, but if I use the checkbox filter, then it gives me different places with all of those tags regardless of the state location. Can someone help me with this?
The goal is to use the dropdown filter, then once the location shows… I want to be able to filter by category like “outdoor seating”, “pet friendly” and it show the correct info by state.
Here is the code:
//code for the dropdown
import wixData from ‘wix-data’ ;
$w . onReady (() => {
$w ( “#dropdown3” ). onChange ( function () {
search ();
});
});
function search ( ) {
wixData . query ( "Breweries" )
. contains ( "locations" , String ( $w ( "#dropdown3" ). value ))
. find ()
. then ( results => {
$w ( "#listRepeater" ). data = results . items ;
});
}
//code for checkbox
const databaseName = ‘Breweries’ ;
const databaseField = ‘tags’ ;
$w . onReady ( function () {
$w ( '#selectionTags1' ). onChange (( event ) => {
**const** selectedBox = $w ( '#selectionTags1' ). value ;
addItemstoRepeater ( selectedBox );
})
});
function addItemstoRepeater ( selectedOption = []) {
**let** dataQuery = wixData . query ( databaseName );
**if** ( selectedOption . length > 0 ) {
dataQuery = dataQuery . hasSome ( databaseField , selectedOption );
}
dataQuery
. find ()
. then ( results => {
**const** filtereditemsReady = results . items ;
$w ( '#listRepeater' ). data = filtereditemsReady ;
})
}