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) + '...';
});
});
}
@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?
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.
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!!
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:
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! thanks my friend!