GetCurrentItem temperamental with a lightbox


I’ve got a page containing a repeater. When a user clicks the editButton in the repeater on said page, two things happen:

  1. a lightbox is displayed to allow a user to edit the details displayed in the repeater
  2. the lightbox is populated with the relevant information about the item that has been clicked in the repeater e.g. price, name etc

When I first open the page and click the edit button it works perfectly. The lightbox opens and it’s populated with the correct info.

However, when I close the lightbox and go back to edit the details of another item in the repeater upon clicking the edit button the lightbox opens but it is populated with the details of the most recent item in the database not the clicked item.

Code is below:

$w.onReady(function () {
    $w("#dataset3").onReady(() => {
        // console.log($w("#dataset3").getCurrentItem()["_id"])
        $w("#editButton").onClick((event) => {
            let item = $;
            let id = item("#dataset3").getCurrentItem()["_id"];

            let carInfo = item('#dataset3').getCurrentItem();

            wixWindow.openLightbox('Edit Your Car', carInfo)
                .then((data) => {


Any advice would be greatly appreciated! Thank you

Wix Team - any advice would be brilliant :slight_smile: Thank you in advance

I think getCurrent item will not work in your situation.

Instead use…$w/repeater/introduction

For a repeater populated by connecting it to a dataset:

$w.onReady( function () {
  $w("#repeatedContainer").onClick( (event) => {
    let $item = $;
    let clickedItemData = $item("#myDataset").getCurrentItem();
  } );
} );

Another possibility could be to use the INDEX inside the REPEATER-SCOPE in combination with…

$w.onReady( () => {
2  $w("#myDataset").onReady( () => {
3    $w("#myDataset").getItems(3, 2)
4      .then( (result) => {
5        let items = result.items;
6        let totalCount = result.totalCount;
7        let offset = result.offset;
8      } )
9      .catch( (err) => {
10        let errMsg = err.message;
11        let errCode = err.code;
12      } );
14  } );
16} );

Sorry, not enough time to explain in detail.

Thanks @russian-dima

Re the first code block unless I’m missing something that looks like what I’m doing at present right?

Re the second code block I’ve taken a look at the link but can’t see how I’d identify which container for the repeater was clicked based on getItems() - any advice to steer on the right path would be super

I took a closer look onto your issue. You are right.

After opening once the lightbox…
let $item = $w . at ( event . context );
… does not work anymore, even when you close lightbox again.

I still could not find the issue for this behaviour.

I would recommend you to work completely WITHOUT DATASETS!!!

If you can code = you don’t need DATASETS.

Instead work with WixData-API.