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

Getting Row Count

3 Answers 45 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Jeremy Robinson
Top achievements
Rank 1
Jeremy Robinson asked on 21 Jun 2010, 08:50 PM
Hi All,

I have a RadEditor on my ASP.NET page.
I want to get the number of lines users have entered and want to restrict users to enter more than X lines.

Is there are property of RADEditor using which I can achieve this ?

Thanks

3 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 22 Jun 2010, 08:06 AM
Hello Jeremy,

RadEditor does not offer the required feature to limit the lines because the HTML markup is just a string it is not able to determine if the text entered will fit in a certain amount of space. However, you can enhance the provided code below to fit your scenario. Here is a basic example on how to limit the line length in the editor content area:

<telerik:RadEditor ID="RadEditor1" OnClientLoad="OnClientLoad" runat="server"></telerik:RadEditor>
<script type="text/javascript">
function OnClientLoad(editor)
{
    editor.attachEventHandler("onkeyup", function(e)
    {
        var brs = editor.get_document().body.getElementsByTagName("BR");
        if (brs.length > 2)
        {
            alert("You can only have 3 lines of text! Undoing last operation!");
            editor.undo(1);
        }
    } );
}
</script>

Here is a another base solution which will help you to achieve your scenario:

<script type="text/javascript"> 
 
function checkEditor(editor, ev) 
{    
    var targetHeight = editor.get_document().body.scrollHeight; 
    var allowedHeight = editor.AllowedHeight; 
 
     
    if (targetHeight > allowedHeight) 
    { 
        alert("Maximum allowed size content height is 350 pixels"); 
         
        if (ev) 
        { 
          ev.returnValue = false; 
          ev.cancelBubble = true; 
        } 
         
        return false; 
    } 
    return true; 

 
function OnClientCommandExecuted(editor,commandName, tool) 

    var allow = checkEditor(editor); 
     
    if (false == allow) 
    { 
        editor.undo(1); 
    } 

 
function OnClientLoad(editor) 
{    
   //Set content area to be one inch high 
   var iframe = editor.get_contentAreaElement(); 
   iframe.style.height = "350px"; 
   iframe.style.border = "1px solid red"; 
    
   editor.AllowedHeight = iframe.offsetHeight; 
    
    var resizeFnRef = function (e){checkEditor(editor, e)}; 
  
    editor.attachEventHandler("keydown", resizeFnRef); 
 

</script> 
<telerik:RadEditor id="RadEditor1"  
    Height = "350px"
    OnClientLoad="OnClientLoad"
    OnClientCommandExecuted = "OnClientCommandExecuted"
    Runat="server">
</telerik:RadEditor>



Sincerely yours,
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
Bharani
Top achievements
Rank 1
answered on 28 Apr 2015, 01:51 PM

Hi Ruman,

i am able to get alert if the row crossed, however it is not removing the extra row. 

for copy and paste also it is not working.

please provide solution 

0
Bharani
Top achievements
Rank 1
answered on 03 May 2015, 09:29 AM

Any help!

I am able to get number of rows, however it is not removing the content when it reached max level

Tags
Editor
Asked by
Jeremy Robinson
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Bharani
Top achievements
Rank 1
Share this question
or