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

Editor Content A Fixed Size??

1 Answer 99 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Dean
Top achievements
Rank 2
Dean asked on 24 Nov 2008, 12:02 PM
Hi,

I need the content that a user can edit, to be a fixed size.. eg- the user can only edit whats viewable in the editor
and not be able to increase the size of the page, kinda like a masterpage contentcontrol.
________________
This is a Title

This is Description

This is Ending notes
________________

So everything inbetween the lines can be edited but the line width and height cannot be increased or descreased (Fixed)

Is this at all possible?

Regards

Dean

1 Answer, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 24 Nov 2008, 04:04 PM
Hi Dean,

RadEditor does not offer the required feature built-in and 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> 

Kind regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
Dean
Top achievements
Rank 2
Answers by
Rumen
Telerik team
Share this question
or