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

RadEditor pasteHtml give's strange result

1 Answer 60 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 21 May 2015, 09:09 AM

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

1 Answer, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 26 May 2015, 03:47 AM
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
Tags
Editor
Asked by
Peter
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Share this question
or