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

Stuck in header

3 Answers 36 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Niklas Lindwall
Top achievements
Rank 1
Niklas Lindwall asked on 14 Nov 2008, 12:23 PM
Hi,

This has been a problem for us for quit some time now and I really would like to sort this out once and for all!

Try this in IE7 in your current demo.
  • Enter html mode and wipe out all the content.
  • Back to edit mode
  • Enter some text and mark this text
  • Choose paragraph style and some heading
  • Now hit the enter key
  • You are now stuck in the header!

This seem like a really basic thing to do but obviously it's not?
If you look at the code in html mode it looks like for example:
<h1>
<p>Heading 1</p>
</h1>

The odd thing is that if you do the same thing as described above, but you don't mark the text.
Just let the cursor be after the typed text. Then everything work as expected:

<h1>Heading 1</h1>
<p>Bla Bla</p>

We would also like to use NewLineBr set to false. I don't know if this is an issue together with the above but I suspect so.
Are there any workarounds?

Regards
Niklas



3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 18 Nov 2008, 08:31 AM
Hi Niklas,

We are aware of this behavior and it is logged in our todo list for enhancement. The issue is due to that IE automatically wraps the content inside P tags if it does not contains any other <p> tags in it. That is why you should not experience this problem if you have more paragraphs in the content area.

Nevertheless, my suggestion is to temporary use the following workaround which will strip the P tags inside the headings using regular expressions:

    <script type="text/javascript"> 
    var selectionExists = false; 
 
    function OnClientCommandExecuting(editor, args) 
    { 
       if (args.get_commandName() == "FormatBlock") 
       { 
          selectionExists = editor.getSelection() ? true : false;  
       } 
    } 
 
    function OnClientCommandExecuted(editor, args) 
    { 
       if (args.get_commandName() == "FormatBlock" && selectionExists) 
       {           var theHTML = editor.get_document().body.innerHTML; 
           alert(theHTML); 
           theHTML = theHTML.replace(/<p>/gi, "").replace(/<\/p>/gi, ""); 
           alert(theHTML); 
           editor.get_document().body.innerHTML = theHTML;        
        } 
    } 
</script>  
<telerik:RadEditor ID="RadEditor1" NewLineBr="false" OnClientCommandExecuting="OnClientCommandExecuting" OnClientCommandExecuted="OnClientCommandExecuted" runat="server"> 
</telerik:RadEditor> 

Best regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Niklas Lindwall
Top achievements
Rank 1
answered on 18 Nov 2008, 09:45 AM
Hi,

Thanks for the answer.
This works fine in a empty page but it dosen't work very good in a page that contains several paragraphs since it grabs the whole body and replaces everything.
Isn't there a way to do this only on the selection?

Regards
Niklas
0
Rumen
Telerik team
answered on 21 Nov 2008, 10:15 AM
Hi Niklas,

My suggestion is to override the editor's FormatBlock command with the FormatBlock command of the browser and see whether you will still experience this problem. Here is an example:

<script type="text/javascript">
function OnClientCommandExecuting(editor, args)
{
   //The command name
   var commandName = args.get_commandName(); 
   if (commandName == "FormatBlock" )
   {
       //The selected value
       var value = args.get_value();
     
    editor.get_document().execCommand("FormatBlock", null, value);
 
   args.set_cancel(true);
}
}
</script>
<telerik:RadEditor ID="RadEditor1" runat="server" OnClientCommandExecuting="OnClientCommandExecuting">
    <Content>
        Sample content
    </Content>
</telerik:RadEditor>

You can use the solution above until our developers fix the problem.

Best regards,
Rumen
the Telerik team

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