Hello I read thru the forums and instructions for doing this but I can’t get it to work. I’m new to Velo coding and it’s likely a missing element or syntax error.
Can you help me?
Objective: Display a repeater for Google Reviews on a website (see the bottom of page @ marleysgothamgrill.net for example of repeater displayed). I need to set the amount of text displayed to be consistent so that the repeater block does not expand and stays uniform.
Reference: I referenced the site front end home page above to see the example of what I’m trying to manipulate and control. Here is also the home page code I inserted.
Issue: I noticed that the text52 element is noted with an error msg but I dont know how to fix it?
Field Definitions:
dataset1 - my content manager collection ID
repeater2 - the repeater ID shown on the home page
text52 - the text field in the repeater.
Note: this text data is mined from the dataset “comment” field name.
button12 - the Read More text button I placed into repeater.
// Velo API Reference: https://www.wix.com/velo/reference/api-overview/introduction let fullText; // variable to hold the full text let shortText; // variable to hold the short version of the text //$w.onReady(function () { // Write your Javascript code here using the Velo framework API // Print hello world: // console.log("Hello world!"); // Call functions on page elements, e.g.: // $w("#button1").label = "Click me!"; // Click "Run", or Preview your site, to execute your code $w("#dataset1").onReady(function () { const shortTextLength = 40; fullText = $w('#dataset1').getCurrentItem().textField; if (!fullText) { $w("#repeater2").forEachItem( ('#text52')).collapse(); $w("#button12").label = "Show Less"; } else { if (fullText.length <= shortTextLength) { $w("#repeater2").forEachItem( ('#text52')).text = fullText; $w("#button12").label = "Show More"; } else { shortText = fullText.substr(0, shortTextLength) + "..."; $w("#repeater2").forEachItem( ('#text52')).text = shortText; } } }); //});
OK that $item and itemdata and index is literal?? I see! I will try this!
I also ready about Multi-State boxes. Never realized that I’m not using one in my repeater. Must I be for this to work?
Should I also follow this lesson too? https://support.wix.com/en/article/velo-tutorial-expand-text-with-a-read-more-link
Hello!
Hope you're liking Velo so far. :) You're right that this is a syntax issue -- take a look at the documentation for forEachItem if you haven't already if you're confused about the syntax.
Taking your first if statement, you'll have to set it up to look something like this:
$w("#repeater9").forEachItem(() => { $w('#text52').collapse(); $w("#button12").label = "Show Less"; });
forEachItem basically loops through all of your Repeater items. In the callback part of the function (within the curly braces), you'll code as you would anywhere else, using the $w selector and all -- the difference being that anything you do inside the repeater's forEachItem loop will be applied to all repeater items.