Lightbox Code Can't Access Form Elements - Getting 0 Elements with $w('*')

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(); // :white_check_mark: This works
console.log(context.productName); // :white_check_mark: 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 :white_check_mark:
  • Admin receives form notifications :white_check_mark:
  • Users receive emails (but with {{field_name}} instead of actual values) :white_check_mark:

The Goal: I need to set the hidden field values dynamically so my email template shows actual product data instead of {{product_name}}.

Questions:

  1. Why would $w('*') return 0 elements when the form clearly exists?
  2. Is there a timing issue with when form elements become accessible?
  3. Are there restrictions on accessing form elements in lightboxes?
  4. Alternative approaches to pass dynamic data to email automations?

Any help would be greatly appreciated!

Wix Forms do not expose form fields to Velo, especially when embedded inside a lightbox. (well not since I last tried)

Instead of using the Wix Form element maybe try build a custom form.

or if you have to stick with wix forms maybe pass the context to the email automation directly.

1 Like

Thank you so much! Will give your suggestions it a try.

If you choose to stick with the Wix Form widget, I’d recommend reading the docs for it - Wix Forms V 2 Introduction | Velo

You can set field values using - https://dev.wix.com/docs/velo/velo-only-apis/$w/wix-forms-v2/set-field-values - which reading between the lines is what you’re aiming to do, right?