On Lightbox Close [Solved]

Hello,

Is there a way to send data back to a page upon close? I know there is a way to send data on open of a lightbox, but unsure on the close side.

For example, I want to open a lightbox, have a user enter data, and then when the lightbox closes I want to refresh a repeater on the page. I need to refresh repeater to trigger / start when the lightbox closes.

Thanks in advance!

How do I pass data between a page and a lightbox?
When you open a lightbox using the openLightbox() function, you can pass an object containing data to be used in the lightbox. In the lightbox’s code, you call the getContext() function to retrieve the data sent by the openLightbox() function.

When you close the lightbox using the close() function, you can pass an object containing data to be used by the page that opened the lightbox. This data is retrieved from the resolution of the Promise returned by the openLightbox() function.

https://www.wix.com/corvid/reference/wix-window.lightbox.html

Thanks for this. I’m getting the promise to trigger, but I keep getting a null error.

//Page Code:

import wixWindow from 'wix-window';

export async function addPointButton_click(event) {
  $w('#addPointButton').hide();
  $w('#addPointSpinner').show();
 await wixWindow.openLightbox("AddPoint", {
 "row1": "hi"
  })
  .then( (data) => {
 //Wait for data coming back
    console.log(data)
  } );
  $w('#addPointSpinner').hide();
  $w('#addPointButton').show();
}

//Lightbox Code

import wixWindow from 'wix-window';

$w.onReady(function () {
 let receivedData = wixWindow.lightbox.getContext();
    console.log(receivedData);
});

export function closeXButton_click(event) {
 let data = {"refresh_info": false}
  wixWindow.lightbox.close(data);
}

Any suggestions? I’m getting it to print “row1”: “hi” on lightbox open, but when it closes I’m getting null.

Thank you!

@geekbetting I will guess you’re using the lightbox’s native X button that is set to close the lightbox without code. Try using a different button and see if it works,

@geekbetting
For more on what J . D. means, have a look at the close function info from the API reference for it.
https://www.wix.com/corvid/reference/wix-window.lightbox.html#close
To pass data back to the page that opened the lightbox, you must close the lightbox programmatically using the close() function. If the lightbox is closed by the site visitor clicking the ‘X’ icon, close button, or lightbox overlay, data will not be passed back to the page that opened the lightbox. Therefore, if you want to make sure data is passed back to the page that opened the lightbox, disable all of the methods mentioned above and create your own method for closing the lightbox programmatically. For example, you can add a button with an onClick event handler that calls the close() function.

Close the lightbox and pass back data to the opening function

import wixWindow from 'wix-window';

// ...

wixWindow.lightbox.close(dataObj);

Plus, there are a good many code samples in the Lightbox section that you can look at, like this in the close reference.

/*****************
 * Lightbox Code *
 *****************/

import wixWindow from 'wix-window';

$w.onReady( function () {
  let received = wixWindow.lightbox.getContext();
  $w('#lightBoxReceive1').text = received.pageSend1;
  $w('#lightBoxReceive2').text = received.pageSend2;
} );

export function closeButton_click(event) {
  wixWindow.lightbox.close( {
    "lightBoxSend1": $w('#lightBoxSend1').value,
    "lightBoxSend2": $w('#lightBoxSend2').value
  } );
}

Thanks guys. I disabled https://support.wix.com/en/article/setting-how-your-lightbox-is-closed and then coded out a different X button and it worked perfectly. Thank you!!!