Rich text in repeaters all showing the same information after I code a "read more" button

Hi all, I’m trying to create a “read more” button so that readers don’t have to read a chunk of words/ so my repeaters are all the same size (as no. of words are standardised). One thing to know is, the description I’m trying to collapse is Rich Text in a dynamic page, connected to a database. I have changed all .text to .html instead. However, it seems that after including the code for the “read more” button, ALL my descriptions are the same. This means that instead of the usual dynamic page linking (repeaters show diff information), the repeaters now all have the same information.

This is a screenshot of my code:


(#ProfsData is the name of my dataset)
(#researchInterests is the name of my text element in the repeater, and also the name of my field ID in database. They don’t mix since one needs a # in front of it)
(#readMore is the name of my button to read more)

And this is the aftermath AKA my problem:


Both repeaters show the same information! However, the names, photos, links, emails are all correctly linked to the database, that’s why they are all different (and correct!) Only the description (researchInterests) is wrong and the one I’m attempting to write a code for.

If someone can help me with this, I would greatly appreciate it!

If it’s rich texts, you should do it like that:
https://www.wix.com/corvid/forum/main/comment/5d38ab84b70dc6007513140e

But put it inside repeater.onItemReady() :
https://www.wix.com/corvid/reference/$w.Repeater.html#onItemReady

and use $item instead of the $w

Hi J.D.,
Thank you for replying! However I’m not used to coding so I ran into some issues.

I don’t really understand the whole repeater.onItemReady() thing HAHA. I’ve done what you’ve mentioned in the other forum post (2 text boxes) and tried to put the code inside repeater.onItemReady(). Do I have to copy the whole code from the page you redirected me to? I just used the first opening line:

How do I define $item? And do I do anything about the $item/ itemData/ index part?

@yitingter use $w (#repeater1")
But inside the function, use $item:
like: $item(“#researcgInterests2”).collapsed etc…

@jonatandor35 Okay, it does expand and collapse when I click the “read more” button. However, the console says that “TypeError: $item(…).collapse is not a function” whenever I collapse something.

Even though I can expand/collapse, the text is still “research 1” and “research 2” since those are the 2 text boxes I added. How do I make them connected to my dataset in order to show short and full text? Maybe the problem was that I used only the first line of the repeater.onItemReady code you linked me… should I have copied the whole code that was written?

Also, do I use any of my previous lines of code (first post) or completely disregard them?

(This is the only piece of code regarding this issue, nth on top or below it)

Thank you J. D. in advance cos I’m really trying to get this right!

For example, I can’t see how “research 1” (short text) will be the shortened version or “research 2” will be the full text version without me writing the $w(“research1”).html = shortText etc part.

@yitingter In each repeater item you put 2 textboxes. You connect them both to your collection, one for the full text field and the other to the short text field. and you continue from there.
(Since it’s rich text you can’t just use the substring() method to make it short, and you should hold 2 versions of the texts. Alternatively you can find or write a function that makes the text short and keeps the format, but this is more complicated.

@jonatandor35 Thanks J.D. Now I understand what you meant! Sadly I already have way too much information written on rich text, and to transfer them over to text and shorten them manually, is quite hard (i.e I’m too lazy). Wix database doesn’t have the shortcuts like in Excel :frowning:

Thank you for helping me out though! If one day I were to push through with manually shortening all of my texts, I will use your advice since I understand how it works now. Or if you know what the function is to make rich text short and keep the format, please do let me know HAHA. Although I don’t think there is one right now… all the forum posts with my issue seem to end up unsolved as well.

@yitingter a function for using substring() method without losing the format, depends on the specific format ( a general function that covers all the options is a little bit complicated. So if you have a simple pattern, it’ll be easier to solve).