Hi @gelion42 ,
Please use the following JS code snippet, which will limit the comment length to 10 characters by default. If you want, you can change the character count as needed.
const textarea = document.getElementById('comment');
const maxWordsLimit = 10; // Change this to your desired word limit
// Function to update word count and control input
function updateWordCountAndControlInput() {
const words = textarea.value.trim().split(/\s+/); // Split by whitespace
const wordCount = words.length === 1 && words[0] === '' ? 0 : words.length;
if (wordCount >= maxWordsLimit) {
textarea.value = words.slice(0, maxWordsLimit).join(' ');
textarea.removeEventListener('input', updateWordCountAndControlInput);
textarea.disabled = true;
}
}
// Add input event listener to the textarea
textarea.addEventListener('input', updateWordCountAndControlInput);
// Initial setup
maxWordsDisplay.textContent = maxWordsLimit;
Feel free to let me know if you need any further assistance.
Have a nice day.???