This is a migrated thread and some comments may be shown as answers.

Red line after x words

2 Answers 28 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Erick
Top achievements
Rank 2
Erick asked on 12 Dec 2013, 01:11 PM
Hi,
I'm searching for a solution to limit the editor input to 2000 words, instead of blocking of the input, add a red line after 2000 words and the input can be continued. Same when pasting a large text, after pasting a large text, a red line have to be added after 2000 words.

Can you please help me out with this?

Kind regards,
Jelle

2 Answers, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 17 Dec 2013, 09:10 AM
Hi Erick,

The desired functionality cannot be implemented with the built-in properties of the RadEditor control. You should further implement and customize such logic.

I have prepared a sample customization, which you could follow for the desired customization:
<telerik:RadEditor runat="server" ID="RadEditor1" OnClientLoad="OnClientLoad">
 
</telerik:RadEditor>
 
<script type="text/javascript">
    function OnClientLoad(editor, args) {
        editor.attachEventHandler("onkeydown", function (e) {
            var textLen = getLength(editor.get_text());
            var alowedChars = !!(e.keyCode === 8 || e.keyCode === 46)
 
            if (textLen >= 20 && !alowedChars) {
                addLine(editor, "red", "2px");
                e.preventDefault();
                setTimeout(function () {
                    alert("You have reached the limit of your message!");
                }, 0);
            }
        })
             
    }
 
    function getLength(text) {
        return text.length
    }
             
    function addLine(editor, color, height) {
        var editorContent = $telerik.$(editor.get_contentArea());
        var line = editorContent.has("#uniqueIdentifier").length;
 
        if (!line) editor.pasteHtml('<hr id="uniqueIdentifier" style="background-color: '
            + color + '; height: ' + height + ';" />');
    }
</script>

Note that you can find further information about the used method and the Client-side API in these articles:

Regards,
Ianko
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Erick
Top achievements
Rank 2
answered on 16 Jan 2014, 08:17 AM
Hi,
Thanks for your answer and semi-solution.
We will test and try this in the next version of our application.

Kind regards,
Jelle
Tags
Editor
Asked by
Erick
Top achievements
Rank 2
Answers by
Ianko
Telerik team
Erick
Top achievements
Rank 2
Share this question
or