Maxlength setting for Rich Text Area?

Is there a way to set the maxlength for input in the rich text area? I know with other inputs you can use an html attribute, but the rich text didn’t respond to it. I looked up restricting it via javascript:

var editor = new RichTextEditor("#rich-text-area", { maxHTMLLength: 200 });

But wasn’t sure if it applied to the Weweb rich text editor. I want to be able to restrict the max character length of a post/entry, as well as a minimum. Thanks in advance for any assistance.

Hi, its not possible at the moment but I will add it to the roadmap so you will have a property to configure the max length.

It could be possible with a workflow on change, by checking the length and keeping only the 200 first characters but you will have to count every tag included in the html version of the text. Not super easy to do.

Thanks for your feedback.

Okay, thanks for the clarity and response. I’ll keep a lookout for the future.

I know this is a year late, but here’s what I’m using; it’s not 100% perfect but if you give yourself some buffer room by ~20% or so (e.g. if it’s 100 max chars in reality, make the max chars 80) it is a hacky way to get a really close result

// Assume inputtedHTML contains the HTML string from a rich text box
let inputtedHTML = variables[/* Description Input - value */ 'YOUR WEWEB RICH TEXT INPUT UUID GOES HERE-value'];

// Function to strip HTML tags from a string
function stripHtml(html) {
    // Create a temporary div element
    let temporalDivElement = document.createElement("div");
    // Set its HTML to the input html
    temporalDivElement.innerHTML = html;
    // Use the textContent property to get the text without HTML tags
    return temporalDivElement.textContent || temporalDivElement.innerText || "";
}

// Use the stripHtml function to get the text content without HTML tags
let textContent = stripHtml(inputtedHTML);

// Calculate the total characters in the textContent
let totalCharacters = textContent.length;

// Define the maximum allowed characters
const MAX_CHARACTERS = 3000;

// Calculate the remaining characters
let charactersRemaining = MAX_CHARACTERS - totalCharacters;

// Return or use the charactersRemaining as needed
return charactersRemaining + ' characters remaining'; // This will print the remaining character count and specified text after it

1 Like