Repeater text is shown as HTML after characters limitation

Hi Everybody!

I have a Rich Text input field in a form, where users can add the description of a property. This input field connects to an also rich text field on my database “Venda”, here called #dataset2. The field key of that field is “descricaoImovel”.

This field is displayed in a text box (“#textdescription”) on the repeater, along with 2 other text boxes. I inserted a code to limit the characters of each of those text boxes following the instructions of the following article of wix: https://support.totallycodable.com/en/article/limit-characters-in-a-repeater-using-wix-code

Problem:
It works fine for the other 2 text boxes. But the one text box that should display the content of the field “descricaoImovel” (“#textdescription”) keeps displaying the text with HTML symbols such as


I also keep getting the error message: “Wix code SDK error: The “onItemReady” function of “repeater1” threw the following error: Cannot read property ‘substr’ of undefined”
I suppose it has something to do with the problem but I have no clue what it could be.

I would really appreciate any help or tips! Thanks a lot in advance :slight_smile:


Here is the code:

$w.onReady(function () {

//limit character numer

    $w("#dataset2").onReady( () => {

        $w("#repeater1").onItemReady( ($item, itemData, index) => {
        let theItem = itemData.title;
        var shortTitle = theItem.substr(0,23);
        $item("#texttitle").text = shortTitle + "";
        });

        $w("#repeater1").onItemReady( ($item, itemData, index) => {
        let theItem = itemData.descricaoImovel;
        if (theItem) {
        var shortDescription = theItem.substr(0,192);
        $item("#textdescription").text = shortDescription + " . . . ";
        }
        });
        
        $w("#repeater1").onItemReady( ($item, itemData, index) => {
        let theItem = itemData.enderecoV;
        var shortEndereco = theItem.substr(0,35);
        $item("#textaddress").text = shortEndereco + "";
        });
    });
});

1 Like

The rich text column in your database contains text with HTML tags so if you try to display it with code it will show the tags. You have 2 options:

First: Instead of $w(“#myText”).text use $w(“#myText”) .html

Second: Eliminate the tags with code like below

var string = itemData.descricaoImovel;
let newString = string.replace('<p></p>', '');
var trimmedString = newString.substring(0, 35);
$item("#myText").text = trimmedString + '...';

If there are multiple tags appearing then you will need to remove each one of them.

You are getting the ‘onItemReady’ error because your field must be empty.

Thanks a lot for the quick reply and the help!!!

It worked! Ended up having to replace the tag indeed. Luckily I just needed to replace

, the rest disappeared by itself :slight_smile:

Thank you Shan. It works, but I get some weird black code underneath my text on some items (see attached images).

My code is:

$w.onReady( () => {
  $w("#dataset1").onReady( () => {

    $w("#repeater1").onItemReady( ($item, itemData, index) => {
 let theItem = itemData.longDescription;
 var shortDescription = theItem.substr(0,100);
      $item("#description").html = shortDescription + " . . . ";
    });

  } );
 
} );