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

Word count show different number in telerik editor control

3 Answers 176 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Muhammad Akhtar
Top achievements
Rank 1
Muhammad Akhtar asked on 14 Jul 2010, 11:24 PM
I'm using the latest version of Telerik Editor in my website and there is a problem with Editor word count.
I wrote a document in MS word and did a word count and it shows
words 280,
Characters ( no spaces) 1950 
Characters ( with spaces) 2229

I did a select all and copied the text as plain text in Telerik Editor and it gave me 
Words: 280 Characters: 2237  .
I have attached some screen shots also.
One of the screen shot is from the demo on the website ( just trying to make it sure that it's not the version problem )

var editorList = new Object();
var editorLengthArray = [20, 30];
var counter = 0;
AlreadyAlerted = false;
 
function isAlphaNumericKey(keyCode) {
    if ((keyCode > 47 && keyCode < 58) || (keyCode > 64 && keyCode < 91)) {
        return true;
    }
    return false;
}
 
function LimitCharacters(editor) {
     
    var style = editor.get_contentArea().style;
    style.backgroundImage = "none";
    style.backgroundColor = "white";
     
    editorList[editor.get_id()] = editorLengthArray[counter];
    counter++;
 
    editor.attachEventHandler("onkeydown", function(e) {
        var content = editor.get_text().trim(); //returns the editor's content as plain text
        var words = 0;
        if (content) {
            var punctRegX = /[!\.?;,:&_\-\-\{\}\[\]\(\)~#'"]/g;
            var contentcontent = content.replace(punctRegX, "");
            var trimRegX = /(^\s+)|(\s+$)/g;
            contentcontent = content.replace(trimRegX, "");
            if (content) {
                splitRegX = /\s+/;
                var array = content.split(splitRegX);
                words = array.length;
            }
        }
        var counter = $get("counter");
        counter.innerHTML = "Words: " + words + " Characters: " + content.length + "   <b>(Maximum character length is 2500)</b>";
        e = (e == null) ? window.event : e;
        if (isAlphaNumericKey(e.keyCode)) {
 
            var maxTextLength = 2500;
 
            textLength = editor.get_text().length;
            if (textLength >= maxTextLength) {
                alert('You have exceeded the maximun character count of 2500.');
                //alert('1');
                AlreadyAlerted = true;
                e.returnValue = false;
            }
        }
    });
 
function CalculateLength(editor, value) {
    var textLength = editor.get_text().length;
    var clipboardLength = value.length;
    textLength += clipboardLength;
    return textLength;
}
 
 
function ClientExecuteCommand(editor, args) {
    
        var commandName = args.get_commandName();
        var value = args.get_value();
        if (commandName == "PastePlainText" || commandName == "Paste") {
            var textLength = CalculateLength(editor, value);
            if (textLength >= 2500) {
                if (!AlreadyAlerted) {
                    alert("You have exceeded the maximun character count of 2500.");
                    }
                AlreadyAlerted = false;
                args.set_cancel(true);
 
        }
    }
}
<telerik:RadEditor ID="RadEditor1" runat="server" SkinID="" Width="100%" SpellCheckSettings-AllowAddCustom="false"  ToolsFile="../TelerikRichEditControl/ToolsFile.xml" OnClientPasteHtml="ClientExecuteCommand" Skin="Office2007" Height="300" EditModes="Design" OnClientLoad="LimitCharacters">
 
</telerik:RadEditor><span id="counter">


Really appreciate your help.
Roomi

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 16 Jul 2010, 11:48 AM
Hello Muhammad,

I examined both screenshots and noticed that the content pasted in RadEditor has formatting - the pasted content in RadEditor has green background color, but the original does not.

My suggestion is to strip the initial content in RadEditor before performing your test, because this could cause the problem.

Could you please also open a support ticket and send us the original MS Word document and exact steps how to reproduce the issue?

Kind regards,
Rumen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Muhammad Akhtar
Top achievements
Rank 1
answered on 16 Jul 2010, 05:12 PM
Thanks Rumen for your reply. In demo I know it has a background but in my application where I tried it does not have anything and I only paste plain text. I'm attaching the word document and also another screen shot of it without any formatting.

Steps to create:

Type any thing in MS Word (I'm using 2007 ) version.
Select all do a word count on it. ( Select All --> Review Tab --> Word Count)
Then Copy all of the text from word to Editor and paste only plain text.
and then see the word count it will be different from the word.


Thanks
Roomi
0
Dobromir
Telerik team
answered on 21 Jul 2010, 03:28 PM
Hi Muhammad,

I already answered your support ticket on the subject. For convenience and in order for the answer to be available to the community, I will paste it here as well:

The provided code is a custom solution and it is out of the scope our support. However, I tested the provided code and noticed couple of issues with the regular expression's manipulations of the RadEditor's content. For example <br/>'s are replaced with \n characters, and when the empty characters are replaced, the words get concatenated. When these errors are fixed, I believe the code should work as expected.

In addition, try setting StripFormattingOption="All" to ensure that no unnecessary formatting is left in the content.



Sincerely yours,
Dobromir
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Editor
Asked by
Muhammad Akhtar
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Muhammad Akhtar
Top achievements
Rank 1
Dobromir
Telerik team
Share this question
or