Code for Restricting Repeater Character Length Broken

Hi Corvid Community,

On the homepage of the WIX site I help run there’s a repeater that takes information from a dataset connected to the site blog and displays it as a custom mini news feed for a specific blog category.

Part of the necessary formatting for this repeater has been implementing a character limit for both the titles of the posts and descriptions of the posts so that they maintain a standardized size on the page.

My code had been working fine for the past year and a half until this morning the code seems to have just stopped working on the live site. It weirdly still works correctly in the WIX Editor Preview Mode, and the developer console in preview doesn’t show any warnings.

But on the live site it is not restricting the length of the titles or descriptions at all.

I’ll admit I’m by no means a coding expert and have assembled the code largely by digging through the forums and learning parts of what helped me build this over time, so it may be kind of inelegant.

All of the Code for the page is as follows:

$w.onReady( () => {
  $w("#dataset1").onReady( () => {
 
    $w("#repeater1").onItemReady( ($item, itemData, index) => {
 let theItem = itemData.excerpt;
 var shortDescription = theItem.substr(0,140);
      $item("#description").text = shortDescription + " . . . ";
    });
 
  $w("#repeater1").onItemReady( ($item, itemData, index) => {
 let theTitle = itemData.title;
 var shortTitle = theTitle.substr(0,70);
 if (theTitle.length > 60){ 
      $item("#title").text = shortTitle + " . . . ";
      }
      });
 
  } );
 
} );

Thanks to anyone who can help me rectify this!

First of all when you use the repeater onItemReady() you don’t need the dataset onReady() .

Also you can (should) compress your code like →

$w.onReady( () => { 
    $w("#repeater1").onItemReady( ($item, itemData, index) => {
 let theItem = itemData.excerpt;
 var shortDescription = theItem.substr(0,140);
      $item("#description").text = shortDescription + " . . . ";
 let theTitle = itemData.title;
 var shortTitle = theTitle.substr(0,70);
 if (theTitle.length > 60){ 
      $item("#title").text = shortTitle + " . . . ";
      }
      });
     
 
} );

Hmm, so this compressed code doesn’t seem to be working for me.

After replacing the original code that is only working in preview, this code isn’t working in either as it isn’t truncating either the title or description.

So it ends up like the second example image in the original post in both preview and on a live version of the site.

As an experiment I tried removing the

$w("#dataset1").onReady( () => {

from the old code that only works in Preview, and found that the old code stopped working in Preview as well. If the above line is removed I get the following warning in Developer Console.

Error parsing web-module 'public/pages/mainPage.js': Unexpected token (20:0) while parsing file: public/pages/mainPage.js

Figured I’d just add that information in case it helps anyone looking this over.

Thanks for the attempt!