I have seen some posts but they were all with repeaters.
My situation is simpeler, but could not get the code right (yet)
I have a single dynamic page, connected to a database.
Thus every page is 1 record from the database, so no repeaters etc.
Amount of pages is according to # of records in database (14 in my case).
I have also made 14 lightboxes
Now I want a button on that dynamic page which opens a specific Lightbox, depending on the name in the ‘lightbox field’ in the dataset of the Dynamic page.
I have put the name of the lightbox (fieldname = lightbox) in a separate field in the record in the database.
Below my code:
import wixData from ‘wix-data’ ;
import {wixWindow} from “wix-window” ;
import {local} from ‘wix-storage’ ;
$w.onReady( function () { let dienst = local.getItem(title);
console.log(dienst)
wixData.query( “Projects” )
.eq( “title” , dienst)
.find()
.then(results => { let items = results.items; let firstItem = items[ 0 ];
Even better would be designing 1 dynamic Lightbox form and let the fields be populated by pushing the data from the primary Dynamic page.
But that’s for the advanced
First, make sure that you are using the Name of the Lightbox, and not the Lightbox ID.
I’m not sure that the onClick() as you have it defined will get the proper Lightbox name. I suspect that you might have to save the name in a global variable, or use wix-storage to save it for later. You can then call openLightbox() with the name that you saved.
As you mention at the end of your post, populating the field by sending the data to the Lightbox is the best option. See the openLightbox() API for information on how to send data to a Lightbox. See the Lightbox’s getContext() API to see how to get the data that was passed to the Lightbox.
Thanks. What do ou mean name Lightbox instead of ID? Name is the Name I have given, right?
Anyway, when I only code open lightbox with a fixed name, it doesn’t even open
See code hereunder
Any suggestion pls?
import wixData from ‘wix-data’ ; import {wixWindow} from “wix-window” ; import {local} from ‘wix-storage’ ;