Character limit on template field with HTML

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I have a template field in a table that displays 3 fields with some HTML. Can I limit the maximum number of characters displayed ?
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Mordechai

Mordechai

  • 968 Points 500 badge 2x thumb
it can be done with javascript. see the following link for an example of how it can be done: http://www.yourinspirationweb.com/en/jquery-tips-tricks-how-to-limit-characters-inside-a-textarea/
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Hi Raymond -

You could likely create a UI Only Formula field and incorporate the use of the LEFT formula function.  I've never actually tried using a formula field to emit HTML itself so I'm not sure if it will play nicely but theoretically it should work and save you from having to write the javascript.  If it doesn't work, besides letting Skuid know about it, you could possibly have 3 formula fields that all use LEFT.  The latter option has a shortcoming since you likely really want as much as possible from all three 3 fields chopping off only the last field but possibly it would work for you.

Hope this helps!
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Thanks guys. The UI field and the Salesforce field ideas are a no-go. I found this plug in which seems to do what I want, but I have no idea of how I would get it to run with Skuid. If I wanted to run something like this, what would the basic steps be to make it a field renderer?
http://www.aakashweb.com/jquery-plugi...
Photo of Mordechai

Mordechai

  • 968 Points 500 badge 2x thumb
Wow, seems I completely misunderstood what you were looking for. sorry about that.

to create a custom renderer you can create an in-line snippet, I assume you want to modify the renderer for "READ" but not for "EDIT" mode, based on this here's a sample renderer:

var field = arguments[0], value = arguments[1];
skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
if (field.mode === "read")
{
    //add code here to modify the display. - specifically you'd want to deal wtih "field.element"
    //something along the lines of:
    field.element.collapser({mode: 'words', truncate: 20 });
}
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
In addition to Mordechai's sample code, you'll also need to add a static resource to pull in the collapser code.  If you can find the collapser JS hosted on a CDN, you can just point to that URL.  If you're unable to find it hosted anywhere, you'll need to download the code itself and create a static resource in your org and then point to that.
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
You guys are awesome, thanks for the help. I will give this a whirl and see what I can pull off.