Code working in preview and not live site

Hi I have some very simple code for a gallery that changes two text items one for name and one for description.
The code works fine in preview but no matter what I do I cant get the live code to work.
I have tried creating a collection for the gallery on the front page and I have set the permissions to site content, I also tried custom permissions. I have gone over 10+ posts about this subject but the advice either doesnt apply or I have tried it.

I thought this would take 10 minuets but have spent 6 hours trying to get it right.

Im not the worlds greatest programmer but I am pretty sure this is how you do this.

// API Reference: Introduction - Velo API Reference -
// “Hello, World!” Example: Velo Learning Center

$w . onReady ( function () {
// Write your JavaScript here

// To select an element by ID use: $w('#elementID') 

// Click 'Preview' to run your code 
$w ( '#text41' ). text  =  $w ( '#gallery1' ). currentItem.description , 
$w ( '#text42' ). text  =  $w ( '#gallery1' ). currentItem.title 



  • Adds an event handler that runs when a gallery’s current item changes.
    Read more
  • @param {$w.GalleryItemChangedEvent} event
    export function gallery1_currentItemChanged ( event ) {
    // This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center |
    // Add your code for this event here:
    $w ( ‘#text41’ ). text = $w ( ‘#gallery1’ ). currentItem.description ,
    $w ( ‘#text42’ ). text = $w ( ‘#gallery1’ ). currentItem.title

Have you tried $w.onReady for your database? Tried putting your code inside .then (don’t know if currentItems items returns a promise).

What isn’t working? Is the problem with the gallery display or with the click on an item?

Hi yisreal

the Gallery I’m using doesn’t have name and description by default so I’m trying to add it in.
the problem is the text doesn’t update on gallery1 item change. Works fine in preview. Management will have a hairy scary if they knew how much time I put into this, it’s a 10 minute job max but nothing I do works.

This looks like a regression. I have a site that did pretty much exactly what the original poster is trying to do and this stopped working some time ago. The callback is not invoked on the live site, but it is invoked in preview.

The code in question is super simple, the gallery in question is populated with static contents (i.e. no database is used):

page code:

import { bindTextToGallery } from 'public/util'

$w.onReady(function () {
    bindTextToGallery('#gallery4', '#text14', '#text49')


export function bindTextToGallery(galleryId, textId, subtitleId) {
    const currentItem = $w(galleryId).currentItem;
    if (currentItem) { 
        $w(textId).text = $w(galleryId).currentItem.title;
        $w(subtitleId).text = $w(galleryId).currentItem.description || ''
    $w(galleryId).onCurrentItemChanged((event) => {
        $w(textId).text = event.item.title;
        $w(subtitleId).text = event.item.description || ''