Restricting text character length in repeater

Hi,
I was able to specify the length of display text in a repeater, but when I paginate, it loses the restriction. How can I keep the ability to restrict the DefinitionText in the repeater when navigating through the pagination?
Page: https://www.idassoc.com/product-information-encyclopedia


Here is the code I used, can someone let me know what needs to be cleaned up or what I am missing? thx!

import wixData from “wix-data”;
import wixLocation from ‘wix-location’;
import {local} from ‘wix-storage’;

export function searchBox_keyPress(event, $w) {
console.log($w(‘#searchBox’).value);
filter($w(‘#searchBox’).value);
let debounceTimer
function update() {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#searchBox’).value);
}, 100);
}
}

function filter() {
$w(‘#dataset1’).setFilter(
wixData.filter()
.contains(‘article’, $w(‘#searchBox’).value)
.or(
wixData.filter()
.contains(‘acronym’, $w(‘#searchBox’).value)
)
).then(()=> {
if ($w(‘#dataset1’).getTotalCount()===0) {
$w(‘#noResText’).show();
} else {
$w(‘#noResText’).hide()
}

const shortTextLength = 60;
let fullText;
let shortText;
$w(“#repeater”).forEachItem(($w,item) => {
fullText = $w(‘#dataset1’).getCurrentItem().definition;
if (!fullText.length) {
$w(‘#DefinitionText’).collapse();
} else
if (fullText.length <= shortTextLength) {
$w(‘#DefinitionText’).text = fullText;

        }  **else**  { 
            shortText = fullText.substr(0, shortTextLength) + "..."; 
            $w('#DefinitionText').text = shortText; 
        } 
   } 
   ) 
} 
) 

}

$w.onReady( function () {
$w(“#dataset1”).onReady( function () {
const shortTextLength = 60;
let fullText;
let shortText;
$w(“#repeater”).forEachItem(($w,item) => {
fullText = $w(‘#dataset1’).getCurrentItem().definition;
if (!fullText.length) {
$w(‘#DefinitionText’).collapse();
} else
if (fullText.length <= shortTextLength) {
$w(‘#DefinitionText’).text = fullText;

        }  **else**  { 
            shortText = fullText.substr(0, shortTextLength) + "..."; 
            $w('#DefinitionText').text = shortText; 
        } 
   } 
   ) 
} 
) 

}
)

1 Like

Hello

I saw your site and it is ok on my computer, did you find the solution?

looks hard bro…following

I used a work around instead bc coding seems to really make the site slow. Also decided to eventually pull this project off of WIX bc the code libraries are bloated and cause page performance issues.
The work around was to pull the 1st 50 characters from the description (excel formula) and import a new property in data set called shortDefinition and just map to that. It’s cumbersome bc if i decided I want more or less chAracters to show, I have to reimport instead of just changing a number in code.

Hello guys,
@deleteduser Your code works great! But for some reason the last item in the repeater ignores the code… I really can’t wrap my head around it. Any idea why it does that?


Thanks in advance!

This is an old post and is being closed.

If you want a full example of limiting characters in a repeater,then see Nayeli (Code Queen) tutorial page and video about it from Feb 2019.

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