Hi i am trying to send a string from a page to a lighbox…
the sender code is:
export function image39_click(event) {
let name = $w('#title').text;
local.setItem('targetName', name);
wixWindow.openLightbox('sendChat');
the receiver code in the lightbox:
let name = local.getItem('targetName');
$w("#text70").text = name;
The problem is that #text70 is not updated with the value of #title that i am trying to pass.
Is there something wrong in the code?
The only doubt i have is that in the source page i am using both {session} and {local} for 2 different data transfer: session to receive data from another page, and local to send data to the lightbox
session is different from local . but it looks as if you are using local correctly in your code.
In any case, I would recommend passing data directly to the Lightbox. Something like this:
To open the Lightbox:
let name = $w('#title').text;
wixWindow.openLightbox("sendChat", {'targetName': name});
To get the passed data in the Lightbox:
let receivedData = wixWindow.lightbox.getContext();
$("#text70").text = receivedData.targetName;
Hi Ysrale, it sounds like a better idea… by the way, how many parameters can i pass to a lightbox? How do i arrange your code if i have to pass 2 parameters?
@ademontis You send an object, so you can pass just about any number of parms that you want. Something like this:
{'parm1': val1, 'parm2', val2, 'parm3', val3 }
As you can see, it’s just an object. So, you can pack at it as full as your little heart desires.
BTW - you can also return parms in a similar. If you need that, just refer to the docs for details.
Sadly it does not work
What i am trying to achieve is a messaging system via a database…
to get the target username from its page I connect to the #title text object which gathers the username from the user profile item dataset (it is correctly displayed in the user page) and send the content of #title to the lightbox:
export function image39_click(event) {
let name = $w("#title").text;
wixWindow.openLightbox("sendChat", {'targetName': name});
}
Then inside the lightbox, iuse this code to gather the username and write the message and sender data to the database:
here is the complete code in the lightbox (ID = lightbox1 , name = sendChat)
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixWindow from "wix-window";
let receivedData = wixWindow.lightbox.getContext();
$w("#text72").text = receivedData.targetName;
export function button2_click(event) {
let toInsert = {
senderId: $w('#dataset4').getCurrentItem()._id, //userprofile dataset
senderPicture: $w('#dataset4').getCurrentItem().profileImage,
senderName: $w('#dataset4').getCurrentItem().fullName,
chatMessage: $w('#dataset5').getCurrentItem().chatMessage, //userposts write dataset
_createdDate: $w('#dataset5').getCurrentItem()._createdDate,
targetName: $w('#text72').text
}
wixData.insert("usermessages", toInsert)
.then( (results) => {
let item = results;
console.log("OK")
$w("#dataset5").refresh();
$w("#textBox1").value= " ";
}) ;
}
The problem is: the data does not seem to pass to the lightbox, because if i put another text object in the source page and i use:
export function image34_click(event) {
let name = $w("#title").text;
$w('#text73').text = $w('#title').text;
wixWindow.openLightbox("sendChat", {'targetName': name});
}
in the source page the new #text73 gets the content of #title correctly.
The two lines of code that get the value, need to be in the onReady() function of the Lightbox:
$w.onReady( function() {
let receivedData = wixWindow.lightbox.getContext();
$w("#text72").text = receivedData.targetName;
} );
There might be other issues, but that one is obvious.
OMG now it works i wonder how i could forget about it…
Thank you Yisrael, very much