I’ve had this code running on my site for 3+ years but it stopped working over the few days. It’s a simple database lookup based upon user input using a Repeater. It just returns nothing. Again, it works in Preview mode and I’ve not made any changes to the code in a long time. Did something change? My Sandbox and Live databases are sync’d - here’s a link to the live site: https://www.dakotaboatretriever.com/look-up-tool
No clue how this code runs in Preview or how it was running before…
Import statements must be at the top of the code file. As you can see, you have an error underlined in red . You also don’t even need this import statement as you aren’t using the wix-data API in your code.
The dataset setFilter() function does not return results in the Promise as you have in your code. After the filter is applied, the Repeater will display the newly filtered data. See the setFilter() API for information.
Funny. Okay, I’ve been found out. I’m not a true JS coder but I do come out to the old school of Assembly Language coding. Something has to have changed in the compiler for this not to work now. Can you help me here? This code was cut & pasted from what I found someone else using for finding (looking-up) rental properties. I played with it until it worked. The red error states Module ‘“wix-data”’ has no exported member ‘wixData’. Like I said, something has to have changed in the compiler.
For the 4 parameters entered by the user, my dataset will only return one answer (match). Should be pretty easy. Thanks!
Old school assembly coding - such as IBM 360 assembler?
And, I did help. As I said…
Delete the import statement as it’s not needed and is causing an error.
Delete the line: $w(“#repeater1”).data = results.items; which is also an error. As you can see in your screenshot,itemsis underlined inredsince it doesn’t exist. There is no variableresultsreturned in this Promise.
Hopefully that should fix things up for you (assuming that nothing else is wrong).
I did eliminate the 2 lines of code you suggested, but that now leaves my WixData variable undefined ( Cannot find name ‘wixData’) . $w ( “#dataset1” ). setFilter ( wixData . filter ()
Okay, so here it is again…cleaned up. I’m still getting the same results - it executes properly in Preview mode, but doesn’t when Published.
Could it be Sandbox .vs. Live data? I have sync’d my Sandbox multiple times. But I noticed that now the Sandbox is optional. Should I disable the Sandbox?
@murphyjaneway A dataset.onReady() is only needed once, in the page’s onReady(), to ensure that the dataset is ready when the page is. It is unnecessary and incorrect when used in other places and contexts.
The dataset setFilter() function doesnotreturnresultsin the Promise as you have in your code. After the filter is applied, the Repeater will display the newly filtered data. See thesetFilter() APIfor information.
What that means is that you should delete the line:
$w("#repeater1").data = results.items;
The variable results is undefined.
Even though this line doesn’t seem to break anything (at least in your case), this line is an error and simply doesn’t do anything. It could actually cause an undefined error (results is undefined) and I’m not sure why that hasn’t happened.
Yes, I see. The Repeater expand handles all the display of filtered data. Makes sense. And you are right Yisrael, the results variable does throw an undefined error (on the Console) at execution. I deleted it and it working perfectly. THANK YOU SO MUCH! Very helpful.