RadEditor pasteHtml give's strange result

2 posts, 0 answers
  1. Peter
    Peter avatar
    1 posts
    Member since:
    Sep 2012

    Posted 21 May 2015 Link to this post

    Hi,

    I have the following function inserted in my RichText Commands.js file:

    RadEditorCommandList["InsertAccordion"] = function (commandName, editor, args) {
        var selectedHtml = editor.getSelectionHtml();
        var newHtml = "<div class=\"accordion-rte\">" + selectedHtml + "</div>";   

        editor.pasteHtml(newHtml);

    };

    It should wrap the selected content in a <div> with the css class "accordion-rte".
    Simply enough I thought... But when I have a text like:

    <h2>Heading 2</h2>
    <p>Some text</p>
    <p>Heading 2.1</p>
    <p>put some text here for paragraph 2.1</p>
    <p>Heading 2.2</p>
    <p>put some text here for paragraph 2.2</p>
    <p>Some other text</p>
    <p>&nbsp;</p>

     and I select in design mode the text from "Heading 2.1" to "put some text here for paragraph 2.2" and then exucute my script the result is:

    <h2>Heading 2</h2>
    <p>Some text</p>
    <p>Heading 2.1</p>
    <p>put some text here for paragraph 2.1</p>
    <p>Heading 2.2</p>
    <p>put some text here for paragraph 2.2</p>
    <p>
    <div class="accordion-rte">&nbsp;</div>
    </p>
    <p>Some other text</p>
    <p>&nbsp;</p>

     while debugging I see the newHtml variable is containing the right value. It got messed up somewhere in the pasteHtml function.

    Does anyone has a clue what's going wrong? and how I can get it to work?

    Much appreciated,

    Peter

  2. Ianko
    Admin
    Ianko avatar
    1535 posts

    Posted 25 May 2015 Link to this post

    Hello Peter,

    I have tested with the most recent version of RadEditor and the behavior is not as described. The elements are properly wrapped into the div. The only minor issue is that an additional H2 tag appears due to content filters. Of course, it can be stripped out via the OnClientCommandExecuting or OnClientCommandExecuted event.

    I am attaching a sample page with the most recent trial assemblies, so to test with them, the described scenario.

    Note that with more recent version of RadEditor, RadEditorCommandList is not available in the global scope. You should use Telerik.Web.UI.Editor.CommandList instead.

    Regards,
    Ianko
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top