Truncating text fields in Collection output displays

Hello - is it possible to truncate a text field to a given number of characters, so that the text fields are limited to a specific size, opposed to dynamically expanding when more text wraps over to the next line?

Hoping to avoid the inconsistency in appearance that the wrapped text causes in my repeater display grid (attached) when shifting the adjacent repeater entry. In this case, each repeater is fed from the a collection database with varying input data, but my attempt is for the output display to remain constant, for a cohesive alignment in the grid. I’m open to other ideas as well, but truncating text seems to be my first go to - are there any java script codes available to do so?

Disconnect the text field from the dataset and do this

export function dataset1_ready() { //allow the dataset to be loaded
    $w("#repeater1").onItemReady( ($item, itemData, index) => {
    $w("#repeater1").forEachItem( () => { //loop the function
         var string = itemData.description; //description is the field name in the database
         var length = 195; //total amount of words you want to display onscreen
         var trimmedString = string.substring(0, length);
         $item("#description").text = String(trimmedString) + '...';
         });
    });
}
1 Like

Nice!!

@brett That was a really quick comment! Is this an automated comment function that I don’t know about yet :smiley:

Oh no. I watch this forum like a hawk. You never know when imma swoop in! :slight_smile:

1 Like

@shantanukumar847 thank you tons for the code. Very much appreciated!! Unfortunately, I guess I just don’t know Jscript well enough to make it work. I tried to follow your great directions in the code, but I tried the following and I didn’t see any results. As instructed, i disconnected just the first name field to see if I could notice results, but to no avail.

export function dataset1_ready() { //allow the dataset to be loaded
$w(“#repeater1”).onItemReady( ($item, itemData, index) => {
$w(“#repeater1”).forEachItem( () => { //loop the function
var string = itemData.firstName; //description is the field name in the database
var length = 5; //total amount of words you want to display onscreen
var trimmedString = string.substring(5, length);
$item(“#firstName”).text = String(trimmedString) + ‘…’;
});
});
}

Any advice for what I am still missing??
Can you advise a good online resource to learn Jscript?

You should mark Shan as top comment. :slight_smile:

1 Like

You have entered 5 instead of 0 here:

var trimmedString = string.substring(5, length); //should be 0

Doing this will only show the first 5 characters:

var length = 5; //number of characters

Assuming that dataset1 is the name of the dataset connected to your repeater, have you done this?

Resources for JS:
JavaScript | MDN
https://www.javascript.com/
JavaScript Tutorial
JavaScript Tutorial - Learn JavaScript

1 Like

Shan the man!

1 Like

Shan are you in the code masters group? :slight_smile:

1 Like

@brett Yes Captain :slight_smile:

1 Like

I’m jealous - I so wish I knew this coding like you guys do. I have tried this numerous times and yet to succeed, with a variety of functions. This one remains to elude me as well. I made your noted changes (I think), but still seeing no results on my end.

Another screen grab if it helps.


Regardless, thank you so much for trying to help!!! And greatly appreciate the Jscript links. I gotta git to it and learn this expertise you guys have!!

Thank you again!!

@that1email can you screenshot your database field key and the text element key on your repeater, just like you did for the dataset

Actually this function is very basic, there must be a very small detail you’re missing out

Disconnect the text field from the database

Look carefully at Line 7 of your code, change $item(“#firstName”).text to this $item(“#text45”).text

Note that your text size is already 5 characters and you are trimming it to 5 characters so you won’t see a change, to test it i suggest you increase the number of characters in your database

@shan - YOU daMan!! It’s working!!! I see what I was missing now!! Thank you so frikn much for knowing your stuff!! And thank you for helping!! In all of the attempts I have been on here to try to make something happen - yours is the first!!! Thank you!!!

I changed it to the ‘email’ field since it has a longer string than the ‘firstName’ field:

export function dataset1_ready_1() {
$w(“#repeater1”).onItemReady( ($item, itemData, index) => {
$w(“#repeater1”).forEachItem( () => { //loop the function
var string = itemData.email; //description is the field name in the database
var length = 21; //total amount of words you want to display onscreen
var trimmedString = string.substring(0, length);
$item(“#text47”).text = String(trimmedString) + ‘…’;
});
});
} //Add your code for this event here:

1 Like

@shantanukumar847 Would you be able to help with some more?? Would you know how to launch URLs/Address GPS/Phone numbers/and EMail addresses?

Within my WIX dynamic page, is it possible to launch the active fields that viewers typically expect to launch from their phone screens??

Below is a shot of dbase info in my dynamic page, from which I’d like to be able to launch these activities. Is it possible with Jscript??

@shantanukumar847 Would you be able to help with some more?? Would you know how to launch URLs/Address GPS/Phone numbers/and EMail addresses?

Within my WIX dynamic page, is it possible to launch the active fields that viewers typically expect to launch from their phone screens??

Below is a shot of dbase info in my dynamic page, from which I’d like to be able to launch these activities. Is it possible with Jscript??

I think good ole Shan has answered the initial question. You should investigate and research this and see what you can accomplish. If you still have trouble, come back and ask that question and include the things you’ve done to try to resolve it. Those usually make the best posts! :slight_smile: thanks my friend!