I have a text element #text82 in a repeater #repeater2, connected to a dataset #dataset1. In this text element, I want to only show a max length of character (max 20 characters) from the collection text field (collection field name is “News Content-English” and field key is newsContentEnglish, so #text82 is connected to “News Content-English” in repeater), because the original full text in way too long to show in this repeater. I just want visitors to have a shortened version and then click “Read more” to go to the corresponding dynamic page where they can read full text.
I have inserted this code in the repeater page code, and the text is not getting truncated/shortened when I preview page, so can someone please correct the code please. I am not a developer, so take it easy Thanks!
(The page is not live, as I don’t want to publish until I get this issue sorted out.)
$w.onReady( function () {
$w(“#dataset1”).onReady( function () {
const shortTextLength = 20;
let fullText;
let shortText;
$w(“#repeater2”).forEachItem(($w, item) => {
fullText = $w(‘#dataset1’).getCurrentItem().definition;
if (fullText.length <= shortTextLength) {
$w(‘#text82’).text = fullText;
} **else** {
shortText = fullText.substr(0, shortTextLength) + "...";
$w('#text82').text = shortText;
}
})
})
})