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

Editor inserts h2 tag instead of line break

1 Answer 34 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 19 Jun 2013, 01:17 PM
Hello,

I have the following scenario:
1. configure editor to use br as a line breaks
2. insert mark up into editor
<h2>text</h2>
<span>111</span>
<h2>text2</h2>
<span>111</span>

3.in design mode set cursor before the "text2" and press enter to add an empty line
4. switch to html mode - you get the following mark up
<h2>text</h2>
<span>111</span>
<h2></h2>
<h2>text</h2>
<span>111</span>
an extra h2 tag is added instead of br. How this can be fixed?

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 24 Jun 2013, 02:32 PM
Hi,

Thank you for reporting this problem.

I have created a public item for this issue, so that you can monitor its progress, comment and vote on it here. However, I am sorry to say that I cannot guarantee with any time bound for the fix, as our developers are currently working on already scheduled tasks of RadEditor that have also high priority.

For the time being, I have prepared the following workaround:
<telerik:RadEditor ID="RadEditor1" runat="server" OnClientCommandExecuted="OnClientCommandExecuted">
</telerik:RadEditor>
 
<script type="text/javascript">
 
    function OnClientCommandExecuted(editor, args)
    {
        if (args.get_commandName() == 'EnterNewLine')
        {
            setTimeout(function()
            {
                var selectedElement = editor.getSelectedElement();
                if (selectedElement && selectedElement.previousSibling &&
                    selectedElement.nodeName == selectedElement.previousSibling.nodeName &&
                     /^(<br>)?$/g.test(selectedElement.previousSibling.innerHTML))
                {
                    var br = editor.get_document().createElement('br');
                    $telerik.$(selectedElement).prepend(br);
                    var extraElement = selectedElement.previousSibling;
                    $telerik.$(extraElement).remove();
                }
            }, 0);
        }
    }
</script>

I have handled the OnClientCommandExecuted event and if the executed command is EnterNewLine check for an extra element.
  
You can see how it behaves in this screencast: http://screencast.com/t/1ntRtGOURlo

I have also update your Telerik points for reporting this problem.

Regards,
Nikolay
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 RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Editor
Asked by
Ivan
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or