Limit text length in a database repeater not working with pagination

I am trying to limit the number of characters displayed in a database repeater text box. (For example, I want to display only 50 characters even if the data is 100 characters etc. )

I was able to do this (code below), but now I have this problem:

The code limiting the characters only works the first time the page loads. When you go to page 2 or come back to page 1, the code no longer works and the full length data is displayed.

My site uses pagination.

Here is my code:

$w.onReady(function () {

$w("#dataset1").onReady(() => {
$w("#repeater1").forEachItem(($w) => {
let text = $w("#dataset1").getCurrentItem().authors;
console.log(text);

let shortenedtext = text.slice(0, 10);

if (text.length > 50) {
$w("#authors").text = shortenedtext+" et al ";

    }

   })

 })
})

Does it have something to do with the onReady function? Or something else?
All help is appreciated.

Thank you!

Limit Characters using Wix Code in a Repeater | Load More Button
https://support.totallycodable.com/en/article/limit-characters-in-a-repeater-using-wix-code

I have explored that article. that article is subtracting from the text, not setting a limit.

Thanks for trying to help though!

@GOS do you know whats going on?

Please help.

I know this is old, but this is my solution to this problem:


var characterlimit = 50; 
  $w("#myrepeater").forEachItem( ($item, itemData, index) => {
  let x = $item("#repeaterelement").text; //gets the text 
  let arr = x.split(" "); //parses the paragraph by space into an array 
  console.log(arr.slice(0, characterlimit)); 

^ The answer is within the console log. Just set what’s in the console log to your element text.

let newtext = arr.slice(0, characterlimit); 
  $item("#repeaterelement").text = String(newtext); 

This thread is old and will be closed, if you have any questions or concerns feel free to open up a new thread instead of bumping up old ones.