Code Works in Preview but not in Published?

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

Below is my code:


Any help is greatly appreciated.

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.

:joy: 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, items is underlined in red since it doesn’t exist. There is no variable results returned in this Promise.

Hopefully that should fix things up for you (assuming that nothing else is wrong).

btw - is the button4_click_3() event handler connected to #button4?

Yes

Thanks Yirael. Yes, 360 Assembler. Yes, #button4

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 ()

How do I handle that?

I’m a potato head! I forgot about the filter . Yes, you need the import statement, but only at the beginning of the code file.

360 Assembler! I’ll drink to that. :beers:

Get rid of the brackets in the import statement. Should be like this:

import wixData from 'wix-data';

Damn! Can’t believe I missed that. Brain fart.

I’ll try this. I had to get on a call. Thanks!

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?

Could the problem be a needed $w(“#dataset1”).onReady( () => {…

} ); ?

@guille Import goes at the very top above the onReady function.
maybe that will help.

@james-rondon-jr THAT’S IT! Yes, Yisrael also said the same thing above and I had forgotten to move it there. THANKS ALL! :hugs:

1 Like

@guille You’re Welcome

@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.

I’ll mention again…

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.

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.

The dataset being filtered causes a refresh of the Repeater, and the expand merely displays (expands) the Repeater.

Glad you got it worked out.