On the homepage of my client’s site, I have 3 dropdown options that they can use alongside a button to take them to the page that needs filtering.
They can choose any selection of the three dropdowns, Just 1, 1+2, 1+3, 1+2+3 etc.
The code on the homepage is working, I have checked that all of the values are storing correctly.
The search page dropdowns are working, as they are showing the values from the homepage, however, the actual filtering isn’t being executed. Any help appreciated.
Home Page:
export function searchButton_click(event) {
if ($w('#stateProvince').value.length > 0) {
let stateProvince = $w('#stateProvince').value
session.setItem("stateProvinceSearch", stateProvince)
} else {
let stateProvince = undefined
session.setItem("stateProvinceSearch", stateProvince)
}
if ($w('#city').value.length > 0) {
let city = $w('#city').value
session.setItem("citySearch", city)
} else {
let city = $w('#city').value
session.setItem("citySearch", city)
}
if ($w('#industry').value.length > 0) {
let industry = $w('#industry').value
session.setItem("industrySearch", industry)
} else {
let city = $w('#city').value
session.setItem("citySearch", city)
}
let searchFromHomePage = +'1'
session.setItem("searchFromHomePage", searchFromHomePage)
wixLocation.to("/properties");
}
Page that does the filtering:
$w.onReady(function () {
$w("#propertiesDataset").onReady(() => {
let industrySearchResult = session.getItem("industrySearch");
let citySearchResult = session.getItem("citySearch");
let stateProvinceSearchResult = session.getItem("stateProvinceSearch");
let searchFromHomePageResult = session.getItem("searchFromHomePage")
$w("#stateProvince").value = stateProvinceSearchResult
$w("#city").value = citySearchResult
$w("#industry").value = industrySearchResult
$w("#text200").text = searchFromHomePageResult
if ($w("#text200").text === '1') {
var searchStateProvince = $w('#stateProvince').value
var searchCity = $w('#city').value
var searchIndustry = $w('#industry').value
let filter = wixData.filter()
if (searchStateProvince) {
filter = filter.eq("stateprovince", searchStateProvince)
}
if (searchCity) {
filter = filter.eq("city", searchCity)
}
if (searchIndustry) {
filter = filter.hasAll("industry2", searchIndustry)
}
$w("#propertiesDataset").setFilter(filter)
.then(() => {
session.clear();
})
});