I have created a multistep form by using a slideshow in a Lightbox. When a user clicks the button on the homepage the Lightbox opens (no problem here) but I would like it to open, not on the first slide, but the third slide.
I’ve placed the code in the onReady function, but while all the code around it executes fine, it doesn’t actually do the slide change (though it works fine if done via a button click).
The code (automatic change of slide) also works when the same code is placed in a onReady function on a separate page (ie not a Lightbox).
I’ve tried putting delays and putting the code in .then functions (for example to execute the code after the slideshow expanded etc) but I can’t get it to work consistently.
Any ideas?
import wixWindow from 'wix-window';
$w.onReady(function () {
let contextData = wixWindow.lightbox.getContext()
console.log(contextData)
/ the slide does change automatically when the code is placed on a new page, but not when it is in a Lightbox
$w('#slideshow').expand()
$w('#slideshow').changeSlide(3)
// trying to get it to work by adding some delays etc
/
$w('#slideshow').expand().then(() => {
console.log('slideshow is rendered')
$w('#slideshow').changeSlide(3)
$w('#slideshow').expand().then(() => {
$w('#slideshow').changeSlide(3)
$w("#mainNavGroup").show().then(() => {
$w('#slideshow').changeSlide(3)
console.log('test')
$w('#slideshow').changeSlide(3)
console.log('test')
$w('#slideshow').changeSlide(3)
$w('#slideshow').changeSlide(3)
$w('#slideshow').changeSlide(3)
}).then(() => {
$w('#slideshow').changeSlide(3)
console.log('test')
})
console.log('done')
})
})
})
Yeah sorry the code I posted is just for context. I put the comments in manually. Please ignore the errors.
The point is that the code works (the slide changes) when the code is on a page and the page is loaded. But it doesn’t work (well it works sometimes but inconsistently) when it is in a Lightbox.
The reason that the slide is not the first slide is that in most cases the first slide needs to the the first slide. I only want it to go the third slide when certain contextData is provided (ie, when a different button is pressed on the home page).
I tried your suggestion:
$w ( ‘#slideshow’ ). changeSlide ( 3 ). then ( $w ( ‘#slideshow’ ). expand );
It still doesn’t work.
Please remember the .then chaining was simply done to see if the delays would get the slide change to execute as they should - so it’s just experimentation.
Again, the main issue is - why can I get the slide to automatically change when the code in in the onReady function on a normal page, but not in the Lightbox. What can I do to make this work?
import wixWindow from 'wix-window';
$w.onReady(function () {
let contextData = wixWindow.lightbox.getContext() //passing 'search'
console.log(contextData)
$w('#slideshow').expand()
if (contextData == 'search') {
$w('#slideshow').changeSlide(3)
}
})
I found a workaround - it works if I wrap the slide change in a .then() after a scrollTo function, but it does add half a second of delay. So if there’s a better solution I’m all eyes.