txtRPLC() is working properly on load.
However...
When I call filterNew(), it keeps the changes from the initial txtRPLC() but filtered, and when the filter is reset to all, it only keeps the txtRPLC() changes from the filtered view.
Would like the txtRPLC() to run after a filter is set and on load.
Or
If possible how could I do this txtRPLC function on the dataset itself rather than on the repeater but without actually saving the dataset with those replacements.
^ That, I assume, would make the filter easier to call, wouldnt need to replace text every time.
Any help is greatly appreciated! 😊
import wixData from 'wix-data'; import {local} from 'wix-storage'; $w.onReady(function() { $w("#teamLogins").onReady(() => { $w("#eventArchive").onReady(() => { // console.log(local.getItem("loginState")) if (local.getItem("loginState") === "Login Success") { $w("#repeater2").show(); $w("#box2").show(); $w("#repeater2").expand(); $w("#box2").expand(); let city; let eventType; let month; let year; txtRPLC(); //Initial Repeater forEachItem //City $w('#city').onChange(() => { city = $w('#city').value; //Dropdown Value if (city === "All") { city = undefined; //Resetting this part of the filter } filterNew(city, eventType, month, year) }); //Event Type $w('#eventType').onChange(() => { eventType = $w('#eventType').value; //Dropdown Value if (eventType === "All") { eventType = undefined; //Resetting this part of the filter } filterNew(city, eventType, month, year) }); //Month $w('#month').onChange(() => { month = $w('#month').value; //Dropdown Value if (month === "All") { month = undefined; //Resetting this part of the filter } filterNew(city, eventType, month, year) }); //Year $w('#year').onChange(() => { year = $w('#year').value; //Dropdown Value if (year === "All") { year = undefined; //Resetting this part of the filter } filterNew(city, eventType, month, year) }); } else { $w("#text90").show(); } }) }) }); function txtRPLC() { $w("#repeater2").forEachItem(($item, itemData) => { if (itemData.eventType === undefined) { $item("#text89").text = "N/A"; } if (itemData.dateOfEvent === undefined) { $item("#text88").hide(); $item("#text91").show(); } }) } function filterNew(city, eventType, month, year) { $w("#eventArchive").setFilter(wixData.filter() .eq('city', city) .eq('eventType', eventType) .eq('month', month) .eq('yearOfEvent', year) ) .then(() => { txtRPLC() }) }
I think the problem us with you filter.
You're filtering by undefined values,
For example, if the user has changed the Year Input, but hasn't set the month yet, it'll try to filter the data by an undefined month etc...
What you should do is something like that:
function filterNew(city, eventType, month, year) { let filter = wixData.filter(); if(city){filter = filter.eq('city', city);} if(month){filter = filter.eq('month', month);} if(eventType){filter = filter.eq('eventType', eventType);} if(year){filter = filter.eq('yearOfEvent', year);} $w("#eventArchive").setFilter(filter) .then(() => { txtRPLC() }) }