Hi,
I’d like to pass values to a lightbox. To do so, I consult the Lightbox API and specifically the code example found there which I copy here for your convenience:
1/*************
2 * Page Code *
3 *************/
4
5import wixWindow from 'wix-window';
6
7export function openButton_click(event) {
8 wixWindow.openLightbox("MyLightBox", {
9 "pageSend1": $w('#pageSend1').value,
10 "pageSend2": $w('#pageSend2').value
11 })
12 .then( (data) => {
13 $w('#pageReceive1').text = data.lightBoxSend1;
14 $w('#pageReceive2').text = data.lightBoxSend2;
15 } );
16}
17
18
19/*****************
20 * Lightbox Code *
21 *****************/
22
23import wixWindow from 'wix-window';
24
25$w.onReady( function () {
26 let received = wixWindow.lightbox.getContext();
27 $w('#lightBoxReceive1').text = received.pageSend1;
28 $w('#lightBoxReceive2').text = received.pageSend2;
29} );
30
31export function closeButton_click(event) {
32 wixWindow.lightbox.close( {
33 "lightBoxSend1": $w('#lightBoxSend1').value,
34 "lightBoxSend2": $w('#lightBoxSend2').value
35 } );
36}
My scenario is this: I’ve written an essay with say 10 footnotes. I provide the full text in my webpage along with a number in parentheses (which is a textbox named #fn252) which the user clicks and a lightbox opens that gets the value of the textbox clicked and displays (through a database prepared for that reason) the corresponding footnote. For example:
User visits the page, starts reading and bumps on the Footnote #252:
https://www.screencast.com/t/aGrrEAPHrab1
The user clicks on it and a lightbox pops-up:
https://www.screencast.com/t/GtsDvz5zLsfI
I want the value of the textbox above (252 in this case) to pass to that Lightbox text element (footnoteId) and then according to a database filter, the footnote text box below to get the actual footnote text from the database, as structured here:
https://www.screencast.com/t/UV9ZHVxn
So I tried to make some modifications to the Velo Code Example and I’d kindly like your opinion/advice about its correctness.
1/*************
2 * Page Code *
3 *************/
4
5 import wixWindow from 'wix-window';
6
7 export function fn252_click(event) {
8 wixWindow.openLightbox("bookFootnotes", {
9 "pageSend1": $w('#fn252').value,
10 })
12
19/*****************
20 * Lightbox Code *
21 *****************/
22
23 import wixWindow from 'wix-window';
24
25 $w.onReady( function () {
26 let received = wixWindow.lightbox.getContext();
27 $w('#fnIdReceive').text = received.pageSend1;
28 } );
30
My approach above has problems. In Preview mode, Lightbox opens but the correct value (252) does not pass to the assigned field but some other value loads from the dataset. In Live mode, the Lightbox opens again but with no values at all, whatsoever.
You can check the live site here, containing the pics above:
https://www.civilitas.gr/immigration-history-4251
Any ideas please?