Issues with Repeaters and Slideshows

Hello,

I am having quite a tough time getting things to work as expected when it comes to manually setting/manipulating the data of repeaters. I have tried building a pared down example to show some of the issues I am having. Navigating to -snip- on the published site results in a repeater that doesn’t populate, with this error in the console: “Unhandled promise rejection TypeError: n is undefined”. This page’s repeater will populate correctly in the editor preview. There are two datasets, one with properties and one with associated property photos. The datasets being accessed have general read permissions. On this page I have a button that opens a lightbox. The data used to populate the repeater on the page is passed to the lightbox. The lightbox has a more or less identical setup, from the elements on the page to the code being used; however, in the lightbox, the repeater is housed within a slide on a slideshow.

The lightbox is called as follows:

wixWindow.openLightbox("Bug Lightbox", {property: currentProperty, photos: photos});

Keep in mind, that the repeater on the repeater-bugs page populates correctly in the editor preview, and I’m simply passing the data successfully used to the lightbox.

The lightbox code is as follows:

import wixData from 'wix-data';
import wixWindow from 'wix-window';

const PROPERTIES_SLIDE = 0;
const GALLERY_SLIDE = 1;
const IMAGE_EDIT_SLIDE = 2;

function repeaterOnItemReady($w, item, itemIndex)
{
	console.log("Running onItemReady() for item #" + itemIndex);

	$w("#itemContainer").background.src = item.image;
	
	$w("#itemContainer").onMouseIn((event, $w) =>
	{
		$w("#overlayContainer").show();
	});

	$w("#itemContainer").onMouseOut((event, $w) =>
	{
		$w("#overlayContainer").hide();
	});
	
	$w("#editButton").onClick((event, $w) =>
	{
		$w("#overlayContainer").hide();		
	});
	
	$w("#deleteButton").onClick((event, $w) =>
	{
		$w("#overlayContainer").hide();		
	});
}

$w.onReady(function ()
{
	$w("#editorSlideshow").changeSlide(GALLERY_SLIDE);

	let data = wixWindow.lightbox.getContext();

	console.log("Attempting to set callback for onItemReady()");
	$w("#itemRepeater").onItemReady(repeaterOnItemReady);
	
	console.log("Attempting to set repeater data to empty array");
	$w("#itemRepeater").data = [];

	console.log("Attempting to set repeater data to photos passed to lightbox");
	$w("#itemRepeater").data = data.photos;
});

It’s this last line, seemingly, that is causing a problem. When execution arrives at this point, the following error is observed in the console “TypeError: n is undefined”, and the repeater’s data array is not overwritten.

If we can figure out what is going on with all of this, it might inform some of the oddities I’m experiencing in the main bit of page/code that this is based off of.

Thank you for your time.

Edit: If anyone would care to share how to properly embed code in a forum post that would be appreciated.

1 Like

Okay, so I’ve nested a callback for the photos dataset’s onReady method inside a callback for the properties dataset’s onReady method to ensure my code is only being run once both datasets are ready. With this change, the repeater’s elements do get populated via my code on the published site, whereas previously it would only work in the preview. An issue now is that something breaks regarding references to specific elements in individual repeater items. I think. Before this addition of onReady stuff, in the editor preview I was able to at least observe my overlays showing and hiding as expected:

After the addition, while the repeater will now at least populate on the published site, I get very odd behavior:

I have placed some logging lines in the onMouseOut() handler, and it fires, but the calls to hide() for my overlay containers seem to be ignored.

Again, any help would be very appreciated.

Edit: And now, seemingly of its own accord, the overlay issue has disappeared. This still leaves the problems with the lightbox, where the particular line $w(“#itemRepeater”).data = data.photos; causes the TypeError to manifest. I can’t find the issue though, since the photos key points to an array of data identical to what the page was using before instancing the lightbox.

Okay, I have been making some changes. I now have a dynamic page that I am working off of. Like I have seen in some other forum posts, I would desperately appreciate a Wix staff member, or whatever group of people it is that load up the site in their editor and take a look at it, to examine what is going on here.

The dynamic page can be found under “Editor Pages” in the Site Structure view. For the purposes of testing, I have been using the item with id 2252bb9f-d0e3-4108-a060-a589383f4394. What I am building here is a small editor to change some attributes about a rental property, and to upload and caption photos of said property. The images are in a repeater that I am manually populating with data. The editor is built with a slideshow. The first slide is the general attributes page. This has a thumbnail that can be clicked to take us to the second page. The second slide shows the repeater (gallery of images), and the third slide appears when the user clicks on the edit icon for a particular image. This last slide shows an expanded view of the image, and has a field where a caption can be added.

In the Wix site editor, setting the slideshow to show the first slide (the configuration I am wanting here) causes some strange bugs. For one, please reference the gifs in the previous post. With slide one set to be shown first, upon navigating to the gallery slide the bug described above with the overlays occurs. Hovering over an image in the repeater reveals an overlay with an edit button and a delete button. Clicking the edit button takes the user to the third slide where an expanded view of the image with an input field for captioning is shown. This third slide has a back button. Clicking the button updates the image with the new caption and returns to the second slide. For whatever reason, the data array stored in the repeater only has entries that look like {_id: random-uuid-whatever} instead of my photo objects that have an id, associated property, image URL, description, etc. Thus, when the repeater’s data array is updated all of the images break as there are no longer any image URLs stored in the array’s objects.

If, however, I set slide two to be shown upon navigation to the page, the overlay issue does not present; the overlays hide as expected when the mouse moves off of each respective repeater item. Furthermore, the image editor works as expected. After adding a new caption to some image and navigating back to the gallery slide, the repeater’s data doesn’t mysteriously lose everything but the ids, and the gallery updates and the images remain visible.

This is all very puzzling, and I am quite certain something is broken on your end. Please, please take a look at this thread and investigate the issue.

Hey Nicholas,

I was looking at your site and… sorry for the delay but there’s a lot to look at.

I noticed what you were talking about regarding the overlay with mouseIn and mouseOut. You had two overlays defined for Slide 2. I got the hover problem working by deleting one of the overlays.

Here’s the original Slide 2:


And here it is after I deleted one of the overlays:


After deleting this change the hover (mouseIn/mouseOut) works fine.

I did NOT save the changes since I didn’t want and any conflicts to arise.

Let me know if this works for you and if I’m heading the right direction.

Yisrael

Hi Nicolas,

Trying to populate a repeater nested inside a hover box slide will only work if the specific slide is currently in view.

While we investigate this issue, you should modify your code to await the changeSlide promise and only then populate the repeater:


$w("#mySlideshow").changeSlide(2)
  .then( (newSlide) => {
     console.log(`Done moving to ${newSlide.name}`);
     //begin populating the repeater
   }
); 

Hi Yisrael and Ido,

Thank you for taking the time to look into this.

Yisrael: There is only one overlay per repeater item, I just had two dummy items in the repeater so I could visualize the spacing between items in the editor. I think the reason deleting the second item fixed the hover issue is simply because you had the second slide visible in the editor in order to delete the item before previewing, and thus did not trigger the issue that Ido seems to have addressed.

Ido: Yes, making sure that I only update the repeater after the changeSlide() Promise resolves has alleviated the issue for now. For future reference, how does one embed a code block into a forum post?

Nicholas,

As far as I recall, I attempted to “stay true” to the scenario as stated. When running with two dummy items, the hover didn’t work. When I deleted one of the dummy items, it worked.

Sorry, that’s all I got for you.

To embed a code block:

  • select the code with your mouse

  • when you release the mouse button, a popup menu appears

  • click on {}


Cheers :beers:,

Yisrael