See that all matches. Repeater 1, textElement. Is a new repeater on a new page.
I don’t want to take a lot of your time, but if you can review it later when you have some time I will appreciate it
See that all matches. Repeater 1, textElement. Is a new repeater on a new page.
I don’t want to take a lot of your time, but if you can review it later when you have some time I will appreciate it
@rhitservicesllc it looks like it’s not connected to any data.
It won’t work unless it’s connected to data.
@jonatandor35 Sorry, I just did, same result. Maybe if you can test it yourself and send me some screenshot I can figure it out what I am doing wrong
@rhitservicesllc Try to put the $repeater.onItemReady() inside:
$w("#dataset1").onReady(() => {
//here
})
@jonatandor35 Like this? Didn’t work
$w("#dataset1").onReady(() => {
const maxCharacters = 5;
$w("#repeater1").onItemReady(($i, iData) => {
let textToDisplay = iData.title.substring(0, maxCharacters);
if(textToDisplay !== iData.title){
textToDisplay += "...";
}
$i("#textElement").text = textToDisplay;
})
})
Putting the const outside, before the $w(“#Dataset”) didn’t work either
@rhitservicesllc yes. like this. And all of this inside $w.onReady(() => {/here/})
I just tried it and it worked as expected.
You can see it here (+the code at the page bottom)
https://jonatandor35.wixsite.com/test/short-text
@jonatandor35 Myyy frieeend!!! That worked! just in time because I gotta go, I cant say how much I appreciate it, I wish we have more people like you in this forum. Tomorrow I will compare the codes to see what I was doing wrong so I can keep learning.
Seriously, thank you so much.
You’re welcome
Is there also a way of cutting off the the text after a fixed number of lines or paragraphes?
It depends.
If the line breaks because it reached the element width, so you can’t easily deal with that.
But if you break the lines with \n then you can do what you wanted to do.
For example:
if the text is "Hi \n How are you? \n let’s talk about something \n something something" .
You can count the number of \n 's and cut the text by.
For example:
$w.onReady(() => {
const maxNumberOfLines = 3;
$w("#repeater1").onItemReady(($i, iData) => {
const textLines = iData.title.split("\n");
const shouldCuttOff = textLines.length > maxNumberOfLines;
if(shouldCuttOff ){
textLines.length = maxNumberOfLines;
$i("#textElement").text = textLines.join("\n") + "...";
} else {
$i("#textElement").text = iData.title;
}
})
})
hi! a noob here, how do i apply this code to the text box? do i have to replace the “#textElement” with my text number on my site? can’t make it work