Question:
Can someone tell me how to fix this code so that when the page loads after someone has selected inputs on the previous page, it shows the data that matches, in the repeater? I was able to get the data to transfer to the dropdowns on the left side but for some reason they will not filter the data on the repeater. It works on other pages not linked to another page but when I try to just get the data from the home page, it does not work.
What are you trying to achieve:
The first page with input boxes to select options for the dataset to filters:
Home Page
Selection options section:
Second Page with results of inputted selections:
Results Page
Page that the code is working on with the dropdowns filtering the repeater when selected:
Working Page
The dropdowns on the left and the repeater is on the right side:
I need the working page combined with the home page selections in the dropdowns filtering the repeater on page load and then be able to change the dropdowns and checkmarks after page loads if needed and the repeater will update.
I keep getting an error code for the .setFilter part of the code.
First Page Code:
import wixLocation from 'wix-location';
$w.onReady(function () {
// Add click event handler for search button
$w('#searchButton').onClick(submitSearch);
});
function submitSearch() {
// Get selected values from radio buttons
const bedrooms = $w('#bedschoices').value;
const bathrooms = $w('#bathschoices').value;
const levels = $w('#levelschoices').value;
// Get min and max square footage values
const minSquareFeet = $w('#minInput').value;
const maxSquareFeet = $w('#maxInput').value;
// Construct URL with parameters
let searchParams = `?bedrooms=${bedrooms || ''}&bathrooms=${bathrooms || ''}&levels=${levels || ''}&minSquareFeet=${minSquareFeet || ''}&maxSquareFeet=${maxSquareFeet || ''}`;
let searchResultsURL = `https://blair946.wixsite.com/homeplansource/search-results${searchParams}`;
// Navigate to search results page
wixLocation.to(searchResultsURL);
}
Second Page Code:
import wixData from 'wix-data';
import wixLocation from 'wix-location';
let debounceTimer;
let searchWord;
$w.onReady(() => {
// Extract URL parameters
const urlParams = wixLocation.query;
// Set dropdown and input values from URL parameters
$w('#dropdown1').value = urlParams.bedrooms || "";
$w('#dropdown2').value = urlParams.bathrooms || "";
$w('#dropdown3').value = urlParams.levels || "";
$w('#minValueInput').value = urlParams.minSquareFeet || "";
$w('#maxValueInput').value = urlParams.maxSquareFeet || "";
// Add event handlers for checkboxes
$w("#checkbox1").onChange(filter);
$w("#checkbox2").onChange(filter);
$w("#checkbox3").onChange(filter);
$w("#checkbox4").onChange(filter);
$w("#checkbox5").onChange(filter);
// Set up event handler for min and max value inputs
$w("#minValueInput").onChange(filter);
$w("#maxValueInput").onChange(filter);
// Set up event handler for search bar input
$w("#searchbar").onKeyPress(() => {
const search = $w("#searchbar").value;
debounceFilter(search);
});
// Call the filter function initially
filter();
});
// Function to debounce search filter
function debounceFilter(search) {
if (debounceTimer) {
clearTimeout(debounceTimer);
}
debounceTimer = setTimeout(() => {
filter(search);
}, 200);
}
// Filter function
async function filter(search) {
const selectedTags = [];
const minValue = Number($w("#minValueInput").value);
const maxValue = Number($w("#maxValueInput").value);
// Add selected tags to the array
if ($w("#checkbox1").checked) selectedTags.push("Coastal Home Plans");
if ($w("#checkbox2").checked) selectedTags.push("Craftsman Home Plans");
if ($w("#checkbox3").checked) selectedTags.push("Stephen Alexander Homes Plans");
if ($w("#checkbox4").checked) selectedTags.push("Single Story Home Plans");
if ($w("#checkbox5").checked) selectedTags.push("Townhouse Home Plans");
// Construct filter criteria
let filterCriteria = wixData.query("Properties");
// Add selected tags filter
if (selectedTags.length > 0) {
filterCriteria = filterCriteria.hasSome("type", selectedTags);
}
// Add min and max value filters
if (minValue || maxValue) {
filterCriteria = filterCriteria.between("squareFeet1", minValue, maxValue);
}
// Add search query filter
if (search) {
filterCriteria = filterCriteria.contains("type", search)
.or(filterCriteria.contains("price", search))
.or(filterCriteria.contains("propertyName", search))
.or(filterCriteria.contains("about", search))
.or(filterCriteria.contains("sku", search))
.or(filterCriteria.contains("squareFeet", search));
}
try {
// Set filter on dataset
$w("#dataset1").setFilter(filterCriteria);
// Fetch filtered data
const queryResult = await filterCriteria.find();
const repeaterData = queryResult.items;
// Update repeater with filtered data
$w('#repeaterresults').data = repeaterData;
// Display number of results
const count = repeaterData.length;
$w("#text152").text = count > 0 ? `${count} Results Found` : `No Results Found`;
} catch (err) {
console.error("Error filtering data:", err);
}
}
Page with working code not connected to another page:
import wixData from 'wix-data';
let debounceTimer;
$w.onReady(() => {
// Set up event handlers for each checkbox
$w("#checkbox1").onChange(() => {
filter();
});
$w("#checkbox2").onChange(() => {
filter();
});
$w("#checkbox3").onChange(() => {
filter();
});
$w("#checkbox4").onChange(() => {
filter();
});
$w("#checkbox5").onChange(() => {
filter();
});
// Set up event handler for min and max value inputs
$w("#minValueInput").onChange(filter);
$w("#maxValueInput").onChange(filter);
// Set up event handler for search bar input
$w("#searchbar").onKeyPress(() => {
const search = $w("#searchbar").value;
if (debounceTimer) {
clearTimeout(debounceTimer);
}
debounceTimer = setTimeout(() => {
filter(search);
}, 200);
});
});
// Filter function
async function filter(search) {
const selectedTags = [];
// Add selected tags to the array
if ($w("#checkbox1").checked) selectedTags.push("Coastal Home Plans");
if ($w("#checkbox2").checked) selectedTags.push("Craftsman Home Plans");
if ($w("#checkbox3").checked) selectedTags.push("Stephen Alexander Homes Plans");
if ($w("#checkbox4").checked) selectedTags.push("Single Story Home Plans");
if ($w("#checkbox5").checked) selectedTags.push("Townhouse Home Plans");
const minValue = Number($w("#minValueInput").value);
const maxValue = Number($w("#maxValueInput").value);
let filterQuery = wixData.query("Properties");
// Add filter for selected tags
if (selectedTags.length > 0) {
filterQuery = filterQuery.hasSome("type", selectedTags);
}
// Add filter for min and max values
if (minValue || maxValue) {
filterQuery = filterQuery.between("squareFeet1", minValue, maxValue);
}
// Add search query filter
if (search) {
filterQuery = filterQuery.contains("type", search)
.or(filterQuery.contains("price", search))
.or(filterQuery.contains("propertyName", search))
.or(filterQuery.contains("about", search))
.or(filterQuery.contains("sku", search))
.or(filterQuery.contains("squareFeet", search));
}
// Set filter and count results
const filterResult = await filterQuery.find();
$w("#dataset1").setFilter(filterQuery);
// Display number of results
const count = filterResult.totalCount;
$w("#text152").text = count > 0 ? `${count} Results Found` : `No Results Found`;
// Filter repeater data based on selected tags
let repeaterFilter = wixData.query("Properties");
if (selectedTags.length > 0) {
repeaterFilter = repeaterFilter.hasSome("type", selectedTags);
}
if (minValue || maxValue) {
repeaterFilter = repeaterFilter.between("squareFeet1", minValue, maxValue);
}
if (search) {
repeaterFilter = repeaterFilter.contains("type", search)
.or(repeaterFilter.contains("price", search))
.or(repeaterFilter.contains("propertyName", search))
.or(repeaterFilter.contains("about", search))
.or(repeaterFilter.contains("sku", search))
.or(repeaterFilter.contains("squareFeet", search));
}
const repeaterQueryResult = await repeaterFilter.find();
const repeaterData = repeaterQueryResult.items;
$w('#repeaterplans').data = repeaterData;
}
I’m pretty new to Wix coding so please bear with me and please take that into consideration in your response. The more explanation the better because I most likely don’t know something you are referring to.
Thanks in advance for your help!