How to have "max length" in radeditor?

7 posts, 0 answers
  1. Tgaud
    Tgaud avatar
    58 posts
    Member since:
    Jun 2009

    Posted 23 Jun 2009 Link to this post

    Hi, i dont find the "max length" property in radeditor, where is it??

    i have a varchar(3000) in my database to save the content.
    But i dont know how to limit the content in the properties??
  2. Rumen
    Admin
    Rumen avatar
    14471 posts

    Posted 25 Jun 2009 Link to this post

    Hello Tgaud,

    Here is an example demonstrating how to restrict the text length in RadEditor:

    <script type="text/javascript"
    var maxTextLength = 30; 
    var messageText = 'You are not able to type more than ' + maxTextLength + ' symbols!'
     
     function isAlphaNumericKey(keyCode) 
     { 
          if ((keyCode > 47 && keyCode < 58) || (keyCode > 64 && keyCode < 91)) 
          { 
              return true
          } 
          return false
     } 
     
     function LimitCharacters(editor) 
     { 
         editor.attachEventHandler ("keydown"function (e) 
         { 
             e = (e == null)? window.event : e; 
             if (isAlphaNumericKey(e.keyCode)) 
             { 
                 textLength = editor.get_text().length; 
                 if (textLength >= maxTextLength) 
                 { 
                      alert(messageText); 
                      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 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(messageText); 
                  args.set_cancel(true); 
     
                } 
            }  
     } 
    </script> 
    <telerik:RadEditor id="RadEditor1" OnClientLoad="LimitCharacters" OnClientPasteHtml="OnClientPasteHtml" 
        Runat="server"
        <Content> 
    </Content> 
    </telerik:RadEditor>  


    Best regards,
    Rumen
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Jeremy Coenen
    Jeremy Coenen avatar
    29 posts
    Member since:
    Feb 2006

    Posted 25 Jun 2009 Link to this post

    There appears to be flaws in this code as it does not count a number of characters that I think should be checked.  For example all of the number pad numbers (0-9) are ignored, as well as period,comma, and a host of other relevant characters.  Below is my modified version of isAlphaNumericKey

     function isAlphaNumericKey(keyCode) { 
          if ( 
              (keyCode > 47 && keyCode < 58) || 
              (keyCode > 64 && keyCode < 91) || 
              (keyCode > 93 && keyCode < 112) || 
              (keyCode > 185 && keyCode < 193) || 
              (keyCode > 218 && keyCode < 223) 
             )  
              { 
                return true
              } 
          return false
        } 

  4. rick
    rick avatar
    3 posts
    Member since:
    Jan 2014

    Posted 11 Feb 2014 in reply to Jeremy Coenen Link to this post

    Hi

    Is there no other way to limit text/html insertion without coding?
    It seems wrong to have a Text / HTML char limit without being able to enforce it.

    Is it possible to add a functionality/property, something like CanExceedMaxLength="false"?

    Thank you
  5. Ianko
    Admin
    Ianko avatar
    1957 posts

    Posted 13 Feb 2014 Link to this post

    Hi Rick,

    The above discussion is dated since 2009 year and could be quite outdated.

    The RadEditor control has the MaxHtmlLength and MaxTextLength properties that could be helpful to restrict the content length. You can examine this help article for more information about them.

    If you have further difficulties, please open a formal ticket to us with details about the encountered problems.

    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 UI for ASP.NET AJAX, subscribe to the blog feed now.
  6. rick
    rick avatar
    3 posts
    Member since:
    Jan 2014

    Posted 13 Feb 2014 in reply to Ianko Link to this post

    Hi,

    Yes, i know of the MaxHtmlLength and MaxTextLength properties, but they do not impede the user from exceeding that limit.
    My question is if there is no alternative to the alert displayed when the limit is exceed, or implementing custom code myself.

    Thank you
  7. Ianko
    Admin
    Ianko avatar
    1957 posts

    Posted 13 Feb 2014 Link to this post

    Hello Rick,

    I am sorry for not understanding the origin of required information.

    Unfortunately, the RadEditor control does not provide a built-in functionality for text length limitation. Such approach should be entirely custom implementation, which is built accordingly to the application requirements.

    Although examining the Client-side API of the editor would help you to achieve the desired functionality.

    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 UI for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top