I’m having an issue where my lightbox code can’t access any form elements, even though the form is working properly.
My Setup:
- Repeater connected to CMS collection “Products”
- Each repeater item has a button that opens a lightbox named “Download 2”
- Lightbox contains a form with: 1 email field + 3 hidden fields (Field Keys:
product_name
,product_url
,product_id
) - Form submission works fine - admin receives notifications and users get emails
The Problem: My lightbox code runs successfully, but $w('*')
returns 0 elements. I can’t access any form fields to set dynamic values.
Working Code:
// Main page - this works fine
wixWindow.openLightbox(“Download 2”, {
productName: data.ProductName,
productId: data.ProductId,
downloadUrl: data.ProductUrl
});
// Lightbox code - context works, but no elements found
$w.onReady(function () {
const context = wixWindow.lightbox.getContext(); // This works
console.log(context.productName); // Shows correct data
const allElements = $w('*');
console.log(allElements.length); // ❌ Always shows 0
const formFields = $w('TextInput');
console.log(formFields.length); // ❌ Always shows 0
});
What I’ve Tried:
- Different selectors:
$w('*')
,$w('TextInput')
,$w('Input')
,$w('#field_id')
- Multiple setTimeout delays (1s, 5s, 10s)
- Removing/adding the lightbox code multiple times
- Confirming lightbox name is correct (“Download 2”)
Evidence the Form Works:
- Form submissions trigger email automations
- Admin receives form notifications
- Users receive emails (but with {{field_name}} instead of actual values)
The Goal: I need to set the hidden field values dynamically so my email template shows actual product data instead of {{product_name}}
.
Questions:
- Why would
$w('*')
return 0 elements when the form clearly exists? - Is there a timing issue with when form elements become accessible?
- Are there restrictions on accessing form elements in lightboxes?
- Alternative approaches to pass dynamic data to email automations?
Any help would be greatly appreciated!