+1-888-365-2779
Try Now
More in this section

Forums / Suggestions / In Rad Editor Control how to set the max length size of data

In Rad Editor Control how to set the max length size of data

3 posts, 0 answered
  1. pankaj
    pankaj avatar
    1 posts
    Registered:
    15 Sep 2008
    29 Sep 2009
    Link to this post

    Hi,
    I have problem in setting the max length size of the rad editor control and unable to bound the exceed data copied into the control so that control should not eccept the exceeded amount of the data like control should not take the data more than the specified,
     I use one javascript code to set the max length, but it is unable to stop the copy paste data into the rad editor control and throwing the error due to exceed data size. Javascript code is able to stop the one by one character typing after the maximum limit of the specified but not able to stop the pasted data in Rad editor in one time.
     So Please help me to set the max data length In Rad Editor Control.

    With regards
    Pankaj Tyagi
  2. Mr. Plinko
    Mr. Plinko avatar
    13 posts
    Registered:
    16 Jul 2009
    01 Oct 2009
    Link to this post
    Hey pankaj!

    I found this code a while back at the Telerik Forums.

    <telerik:RadEditor ID="RadEditorHeadline" runat="server" OnClientLoad="LimitCharacters" OnClientPasteHtml="OnClientPasteHtml"
    <Content></Content></telerik:RadEditor> 
            
    <telerik:RadEditor ID="RadEditorPurpose" runat="server" OnClientLoad="LimitCharacters" NewLineBr="False" OnClientPasteHtml="OnClientPasteHtml"
    <Content></Content></telerik:RadEditor>  
     
    <script type="text/javascript"
        var editorList= new Object(); 
        var editorLengthArray = [20,30]; 
        var counter = 0; 
     
        function isAlphaNumericKey(keyCode) 
        { 
            if ((keyCode > 47 && keyCode < 58) || (keyCode > 64 && keyCode < 91)) 
            { 
                return true
            } 
            return false
        } 
      
        function LimitCharacters(editor) 
        {        
          editorList[editor.get_id()] = editorLengthArray[counter]; 
          counter++; 
          
          editor.attachEventHandler("onkeydown"function(e) 
          { 
            e = (e == null)? window.event : e; 
            if (isAlphaNumericKey(e.keyCode)) 
            {   
                var maxTextLength = editorList[editor.get_id()]; 
                    
                textLength = editor.get_text().length; 
                if (textLength >= maxTextLength) 
                { 
                    alert('You are not able to type more than ' + maxTextLength + ' symbols!'); 
                 
                    e.returnValue = false
                } 
            } 
           }); 
            
            var element = document.all ? editor.get_document().body : editor.get_document(); 
            $telerik.addExternalHandler(element, "paste"function(e) 
            {    
                    e = (e == null)? window.event : e; 
     
                    var maxTextLength = editorList[editor.get_id()]; 
                        textLength = editor.get_text().length; 
                         
                        var clipboardLength = window.clipboardData.getData("Text").length; 
                        textLength += clipboardLength; 
                        if (textLength >= maxTextLength) 
                        { 
                            alert('You are not able to type more than ' + maxTextLength + ' symbols!'); 
                            e.returnValue = false
                            return false
     
                        } 
            }); 
        } 
     
        function CalculateLength(editor, value)   
         {   
             var textLength = editor.get_text().length;   
             var clipboardLength = value.length;   
             textLength += clipboardLength;   
             return textLength;   
         }   
           
        function OnClientPasteHtml(editor, args)   
         {   
            var maxTextLength = editorList[editor.get_id()]; 
            var commandName = args.get_commandName();      
            var value = args.get_value();   
               
                if (commandName == "PasteFromWord"   
                    || commandName == "PasteFromWordNoFontsNoSizes"   
                    || commandName == "PastePlainText"   
                    || commandName == "PasteAsHtml"   
                    || commandName == "Paste" )   
                {   
                    var textLength = CalculateLength (editor, value);   
                    if (textLength >= maxTextLength)   
                    {   
                      alert('You are not able to type more than ' + maxTextLength + ' symbols!');  
                      args.set_cancel(true);   
           
                    }   
                }    
         }     
     </script> 
     
    Let me know how that works!
  3. rani p
    rani p avatar
    1 posts
    Registered:
    14 Dec 2009
    20 Dec 2009
    Link to this post

    Hi,

     

    I did tried the code given below.It works fine but when the editor length is maximum and user tries to add hyperlink editor allows user to enter hyperlink even though maximum charactor limit is reached.

    Also once maximum charactor limit is reached user is not allowed to perform (^A^C) kind of actions like paste ,copy etc.
       

    I also tried custom validator approach in which client side validation function is as follows :

    function CheckLength(sender, args) {

     

     

     

    var editor = $find("<%=radedtrEmailText.ClientID%>");

     

     

     

    var strEmailText = editor.get_text();

     

     

    strEmailText = trim(strEmailText);

     

     if (strEmailText.length > 8000) {

     

     

     

    var valMessage = $get("<%=hdnMaxEmailText.ClientID%>").value;

     

     

    sender.errormessage = valMessage;

    args.IsValid =

     

    false; }

     

     

    else {

     args.IsValid =

     

    true;

     }

      

     

    function trim(str) {

     

    return str.replace(/^\s+|\s+$/g, "");

     

     

     }

     
    Here if i enter special charactor like 

     

     

    ╚╝╞╡╧╩╬╣♣♠♥♦☺☻

     

    abcdÃÇÊçä üĀĉö÷ąŒġĚňňňŕįĩîřţƟƵƮƻ ȘȣȧȵȠǶɯɨɤɤɟʈ ʇʍʏʘʔʯ

     

    ڈ٦٭يםנפרתבחי۩ᴥᴡᴚᴞᴂᴋᴱᴭᴳᴮᴨᶚᵷᵽᶃ Ấầ ṘḾἪἬἆỚỡ Ἥ₲₮↑↕∂∆‼

     

    ╚╝╞╡╧╩╬╣♣♠♥♦☺☻

     

    abcdÃÇÊçä üĀĉö÷ąŒġĚňňňŕįĩîřţƟƵƮƻ ȘȣȧȵȠǶɯɨɤɤɟʈ ʇʍʏʘʔʯ

     

    ڈ٦٭يםנפרתבחי۩ᴥᴡᴚᴞᴂᴋᴱᴭᴳᴮᴨᶚᵷᵽᶃ Ấầ ṘḾἪἬἆỚỡ Ἥ₲₮↑↕∂∆‼

     

    ╚╝╞╡╧╩╬╣♣♠♥♦☺☻

    "
     then length returned by sql select len() = 288 and that by
    trim(editor.get_text()).length = 303.

    Can someone help me with same.

     

     

     

     

3 posts, 0 answered