Display only n number of characters of text from Wix database

Hello, I am trying to display the first 300 characters from the Wix database with Wix code, but the code does not run. Help?

$w.onReady( function () {
$w(“#dataset2”).onReady( function (){

if ($w(“#text49”).text.length > 300){
$w(“#text49”).text.slice(0, 300);
}
});
});

It seems like the slice or substring function does not work in Wix.

Hi Melissa ,

Your code is fine and the slice works well, but you’re missing to assign the sliced value to the $w(“#text49”)
so, it should be like this :

if ($w("#text49").text.length > 300){
        $w("#text49").text =$w("#text49").text.slice(0, 20) ; 

Hope this helps!
Best,

Mustafa

Hi Mustafa, thanks so much! That little bit did work. :slight_smile:

I have another problem though - I placed the dataset on a gallery slider so that when the slider changes, the database info also changes. I noticed that the code only works for the first slide and not any other slide after that. Is this a Wix limitation or is there a way around it?

Hi there! Could you show me how to create a hook that would create a company id using the first character of the first two words the use types into the #companyName field, followed by the 6-digit date the user selects in the datePurchased date input field? For instance, if the user typed My Company Name in the #companyName input field, and selected the date 03/27/2019 in the #datePurchased field, the companyId would be stored as MC032719 in the profile database.

This code works perfectly with dynamicDataset too. But how to expand to full text with show more button??

@oviiiivinfo See the Corvid Tutorial: Creating a Show-More Link

I tried this code but the If statement makes the count of characters previous to receiving the content of the database, so, it does nothing.

¿How can I make the If comparition after the “text49” has received the data?