Editor inserts h2 tag instead of line break

2 posts, 0 answers
  1. Ivan
    Ivan avatar
    16 posts
    Member since:
    Oct 2011

    Posted 19 Jun 2013 Link to this post

    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?
  2. Nikolay
    Admin
    Nikolay avatar
    89 posts

    Posted 24 Jun 2013 Link to this post

    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.
Back to Top