Styled Text Editor

Certified Senior Developer

Hello Everyone,

I’m using a Styled Text Editor for my comment thread component. If the character count exceeds 500 characters, I need to trim the text and display a "Show more" link outside the Styled Text Editor.

The problem I’m facing is that the Styled Text Editor stores values with HTML tags, so when I trim the content directly, it can cut through tags and break the markup. This results in invalid HTML and rendering issues.

Has anyone implemented an approach to safely truncate HTML without breaking tags? Any suggestions or best practices would be appreciated.

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    Here is a sample code where text length validation is kept at 20 characters. Hope this help for your case

    a!localVariables(
      local!showFullText: false,
      local!text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum",
      {
        a!styledTextEditorField(
          label: "Styled Text Editor",
          labelPosition: "ABOVE",
          value: if(
            and(
              len(local!text) > 20,
              local!showFullText = false()
            ),
            left(local!text, 20),
            local!text
          ),
          saveInto: {},
          validations: {},
          readOnly: true(),
          sizeLimit: 4000,
          height: "MEDIUM"
        ),
        a!linkField(
          links: a!dynamicLink(
            label: if(
              local!showFullText,
              "Show Less",
              "Show More"
            ),
            value: not(local!showFullText),
            saveInto: local!showFullText
          )
        )
      }
    )

  • 0
    Certified Lead Developer

    That's difficult. I think the markup is pretty simple and uses P-tags for each line. So you could find the next closing P-tag and truncate the text after it.