Add Lightbox close action to the Submit form button

I’m using a Lightbox to get users phone and name to call them back. So my lightbox has a form with two fields: name and phone. There is also a Submit button. I would like the Submit button to also close the lightbox (preferably after few seconds in order for the success message to be displayed).

I’m trying to achieve this with the code:
import wixWindow from ‘wix-window’;

$w.onReady(function () {
});

export function button2_click(event, $w) {
wixWindow.lightbox1.close();
}

Can anyone please help me here? Thank you!

1 Like

Hi,

To close the lightbox with a delay of 3 seconds:

export function button2_click(event, $w) {
     setTimeout(function(){ wixWindow.lightbox.close(); }, 3000);
}

I hope this helps,

Yisrael

1 Like

Thanks, Yisrael!

Looks really simple and should work right away. Though it doesn’t work in preview mode and I can’t check ATM as I can’t publish just yet.

Yisrael, thank you for your help. I still can’t make it work

import wixWindow from ‘wix-window’;
$w.onReady(function () {

});
export function button8_click(event, $w) {
setTimeout(function(){ wixWindow.lightbox1.close(); }, 3000);
}

I am using that for the submit button in www.galvanoschl.cl/galvanos/emblema-de-honor and still can’t make it close after it sent

It said all the time: TypeError: Cannot read property ‘close’ of undefined

Sorry, it should be:

setTimeout(function(){ wixWindow.lightbox.close(); }, 3000);

lightbox and not lightbox1

See more at the wix-window.lightbox.close API

1 Like

It works! Even in preview! the only change I had to made is “export function button2_click_1” adding this _1 as it was said in the floating menu.

1 Like

Hey guys,

I have this same thing - my Submit button is called #button4 and my lightbox is called #lightbox1 . I need the screen to close after 2 seconds of clicking the submit button. So here’s the code i added. But it doesnt work. Can someone help?

import wixWindow from ‘wix-window’;

$w.onReady( function () {
});

export function button4_click(event, $w) {
setTimeout( function (){ wixWindow.lightbox1.close(); }, 2000);
}

Rajiv,

It should be:
setTimeout(function(){ wixWindow.lightbox.close(); }, 2000);

The problem with this is it doesn’t account for a successful form. How do you only close the lightbox once the form is successful?

@Marissa Levy Lerer

I defined a function on the success message text that pops up after you submit a form (change text26 to whatever your text is named)

export function text26_viewportEnter(event) {                         setTimeout(function(){  wixWindow.lightbox.close(); }, 2000); }