I have a dynamic page with a button.
With this button I want to open a lightbox.
I tried and tried but not working.
Now I have hardcoded the name of the lightbox in it, and even then it’s not opening.
Am I missing something?
I have set the name in the properties of the lightbox to HRMCoaching.
I put the code like hereunder. And then in preview click the button.>> Nothing happens
Any suggestions?
import wixData from ‘wix-data’ ;
import {wixWindow} from “wix-window” ;
import {local} from ‘wix-storage’ ;
Now I’m trying to open a Lightbox Dynamically
Depending on the record in the database. In d=the database there’s a field lightbox, where I have filled in the name of the Lightbox. But this doesn’t work yet
Any idea pls?
import wixData from ‘wix-data’ ; import wixWindow from “wix-window” ; import {local} from ‘wix-storage’ ;
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.
A scenario where information is passed between a page and a lightbox
This example demonstrates how to pass data from a page to a lightbox that it opens and from the lightbox back to the page as it closes.
It assumes that the page has:
An open button that is used to open the lightbox.
Two text inputs where information that is to be passed to the lightbox is entered.
Two text elements where information that is passed from the lightbox is displayed.
It assumes that the lightbox has:
An close button that is used to close the lightbox.
Two text inputs where information that is to be passed to the page is entered.
Two text elements where information that is passed from the page is displayed.
import {local} from 'wix-storage'; // ... local.setItem("key", "value");
Key can be whatever name you want the stored item to be called.
Value is where you add the element name, so in your case it would be $w(‘#projectname2’).value.
Examples
Retrieve an item from local storage
import {local} from 'wix-storage';
// ...
let value = local.getItem("key"); // "value"
The value returned here will be the value that is assigned to the name that you have added to the getItem line, so here it would be the value that is associated with ‘key’
Just note that if the ‘#projectname2’ element is a text box, then you might need to change .value to .text instead.
Thanks for your extensive explanations!
It got me some further, but since it is not my basic language I have to dig deeper in it to better understand it.
I had a deadline so I took the help of an external.
Anyway, this is the final result:
import wixData from ‘wix-data’ ; import wixWindow from “wix-window” ; import { local } from ‘wix-storage’ ;
$w.onReady( function () {
$w( ‘#button8’ ).onClick((event) => { let currentItem = $w( ‘#dynamicDataset’ ).getCurrentItem() let lightBox = currentItem.lightbox
wixWindow.openLightbox(lightBox)
});
});