SO I am brand new to Corvid (and mostly very new to coding in general). I have created a database with images where each image has a title, description, date and location. I have a ProGallery that displays the images dynamically from the database. When you click on an image it takes you to a dynamic page with shows the image larger and has additional data. What I want to do is when you click on the image on the dynamic page it will open a lightbox that has certain data from this particular image already inserted into a text field.
Thus far I have managed to get the lightbox to open using the following code added
import wixWindow from 'wix-window'
import wixData from 'wix-data'
export function gallery1_itemClicked(event) {
wixWindow.openLightbox('myLightBox')
now I am completely stuck with how to make certain data from the page go into a lightbox field…
I understand that there needs to be code added to the lightbox -
import wixWindow from 'wix-window';
import wixData from 'wix-data'
$w.onReady( function () {
let text = wixWindow.lightbox.getContext();
but I can’t figure out how and where to define what text needs to be taken from the page and how to insert it into a particular field in the lightbox.
I read the API documentation on the getContext command but I don’t understand how to implement it… any guidance would be very much appreciated
thank you for the reply, but I want that the “contextData” will be dynamic - so it needs to reference the dynamic elements on the page that contain text - such as:
import wixWindow from ‘wix-window’ import wixData from ‘wix-data’
$w.onReady( function () {
})
export function gallery1_itemClicked(event) { let dataObj = {
“title”: $w(“#text27”).text,
“date”: $w(“#text28”).text,
“location”: $w(“#text29”).text,
“description”: $w(“#text30”).text
}
wixWindow.openLightbox(‘Place Your Order’, dataObj)
}
on the lightbox page I add the following to the code:
import wixWindow from 'wix-window';
import wixData from 'wix-data'
$w.onReady( function () {
let text = wixWindow.lightbox.getContext()
$w('#textBox1').value = $w("#text27")
} )
Use semi colons to terminate statements not commas.
What are you trying to do?
The code tries to write three different things to the same element. So each is over writing the other. What other elements do you have on the light box?
I have a form that has a field that has to be filled out with whatever image triggers the lightbox… so:
there is an image which has a dynamically set (from a DB) title, description, location and date which are displayed on a dynamic page, then once that image is clicked it triggers a lightbox which lets the user order the image so its a form that requests info name, phone email etc… and it has a “Note” field where one would write the image they are requesting, and I want that part filled out with the data from the dynamic page.
So all that information needs to go into that field
You can rest assured that before I have come to the forum I have read the information already available - I have looked at that page so many times…
it doesn’t really explain much in the way of what I need… It seems that I am following the entire protocol that is described there but I am not achieving the desired result - hence I am here and asking questions. So if you have any useful suggestions, I am all ears!
@ilyav In addition you need to brush up on your JavaScript string manipulation.
You are trying to create a text field from something that is called an object. Objects contain properties (e.g. dataObj has a property called imageTitle) that you want to build into a string. There are several ways to build strings from object property values. One is called a template literal:
The other way is using concatenation using the ‘+’ character or the concatenation function:
Lastly I suggest you read this link that should get you up to speed with strings:
Well as it turns out my brother who is a developer gave me a simple solution (for him simple - i would never have figured it out) and its not as satisfying as figuring out myself but, in the interests of expediency I implement it. so here is the solution:
Page code:
import wixWindow from 'wix-window'
import wixData from 'wix-data'
$w.onReady(function () {
})
export function gallery1_itemClicked(event) {
let dataObj = {
"Image Title": $w("#text27").text,
"Image Date": $w("#text29").text,
"Image Location": $w("#text28").text,
"Image Description": $w("#text30").text}
wixWindow.openLightbox('Place Your Order', JSON.stringify(dataObj));
}
Lightbox code:
import wixWindow from 'wix-window';
import wixData from 'wix-data'
$w.onReady( function () {
let dataObj = JSON.parse(wixWindow.lightbox.getContext());
let str = '';
let keyMap = ['Image Title', 'Image Description', 'Image Date','Image Location'];
for (let key of keyMap) {
if(dataObj[key]) {
str += key + ': ' + dataObj[key] + '\n';
}
}
$w('#textBox1').value = str;
} )