Using selector tags causes Velo code to break

I’m having trouble with
I’ve added code to truncate a text field in a repeater to a certain length. I also am using the selector tags input element on this repeater (connected to the database tag element). When I test the selector tag, I click either of them once, it works fine. If I then de-select, the velo code that truncates the description length no longer works.

Working in
Wix Editor

Site link

What I’m trying to do
I added some velo code to shorten the description length in the repeater to 100 characters, no matter how long the actual description text entered is. It’s working great, until I select one of the selection tags. For example, if on the site, you load the page, select ‘ebook’ and then click ‘ebook again’, you’ll see that the description of the item under the OTHER tag (infographic) is no longer cutting off at 100 which makes the repeater containers different heights. Same if you then select infographic and then unselect it—as soon as the eBook item reappears, its description is no longer truncated.

What I’ve tried so far
I tried looking into the selector tag events to see if I could re-run this code when an onChange event happens, but that didn’t work.

Extra context
Velo code:

$w.onReady(function () {

  $w("#dynamicDataset").onReady( function () {
    $w("#listRepeater").forEachItem( ($item, itemData, index) => {
      const shortTextLength = 100; // Set your desired character limit
      let fullText = itemData.descriptionOfResource; 
      
      if (fullText.length > shortTextLength) {
      let shortText = fullText.substr(0, shortTextLength) + "...";
      $w('#description').text = shortText; 
    } else {
      $w('#description').text = fullText;
    }
      
    });
  
  });

});

I think you’re pretty close and changing from forEachItem to onItemReady should resolve this :slight_smile:

1 Like

yep, as Noah mentions.

your trucation code is only running once. When you click your selection tags, Wix refreshes the dataset and the repeater items, but your truncation logic is never called again for the new set of items.

$w("#listRepeater").onItemReady(($item, itemData) => {

Thank you! I’ve tried swapping the code but no luck. After I click either of the selectors twice, the items tagged to the other selector (upon reappearing) still lose their truncation. Maybe it’s just a wix bug.

EDIT - wait! You’ve already shared a link :sweat_smile:

Are you able to drop a link to the site?.

Took a look, and I think it’s an impact of using dataset and code.

That said, I think you can do this no-code, using the Collapsible text element. before connecting to the dataset, change the text, and toggle off the “Show button”. Then connect it to the dataset, and use the existing read more button as is.


This will eliminate the need for code and has the added benefit of choosing the number of rows vs characters

1 Like

That worked perfectly! I didn’t realize I could combine the collapsible text element with the dataset. Thank you so much!

1 Like