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

pasteHtml modifies html

4 Answers 88 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Oscar
Top achievements
Rank 1
Oscar asked on 18 Jul 2018, 10:26 PM

Hi I'm using pasteHTML event on radeditor to paste new content on cursor position, if the editor box is empty it works just great, but if there something else and I hit enter it will modify my html making it useless

 

Here is my script:

function Add_Accordion() {
            var Edtr = $find("<%=ContentEditor.ClientID%>");
            Edtr.pasteHtml("<div id=\"accordion\"><h2>Section 1 title</h2><div><p>Text 1</p></div><h2>Section 2 title</h2><div><p>Text 2</p></div></div>");

}

So.. if I add Hello world! on the first line of editor, hit enter and then click the button to add the script above, this is the resulting html...it add tags and duplicates the ids

<div id="accordion">
</div>
<p>Hello world</p>
<div id="accordion">
<h2>Section 1 title</h2>
<div>&nbsp;</div>
</div>
<p>Text 1</p>
<div id="accordion">
<div>&nbsp;</div>
<h2>Section 2 title</h2>
<div>&nbsp;</div>
</div>
<p>Text 2</p>

 

Thanks for your help!

4 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 19 Jul 2018, 01:41 PM
Hello Oscar,

Can you please test by changing the NewLineMode to Br or Div:

<script type="text/javascript">
    function Add_Accordion() {
        var Edtr = $find("<%=ContentEditor.ClientID%>");
        Edtr.pasteHtml("<div id=\"accordion\"><h2>Section 1 title</h2><div><p>Text 1</p></div><h2>Section 2 title</h2><div><p>Text 2</p></div></div>");
    }
</script>
<telerik:RadEditor NewLineMode="br" RenderMode="Lightweight" runat="server" ID="ContentEditor">
    <Content>
    </Content>
</telerik:RadEditor>

Best regards,
Rumen
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Oscar
Top achievements
Rank 1
answered on 19 Jul 2018, 03:25 PM

Hi Rumen, thanks, that worked a bit better but there are still issues. I tried both but Br seems to work better. If for example I intentionally paste an html script without a final closing div that i'd like to close later after adding more sections, the pastehtml event will close it for me.

e.g.running this
Edtr.pasteHtml("<div id=\"accordion\"><h2>Add section title here</h2><div><p>Add section text here</p></div>");

will result on this
<div id="accordion"><h2>Add section title here</h2><div><p>Add section text here</p></div></div>

Regards

0
Rumen
Telerik team
answered on 20 Jul 2018, 01:53 PM
Hello Oscar,

The reported behavior is a browser one.

Each tag is actually a node in the DOM node and if the browser finds a non closed tag, it automatically corrects and closes it. This cannot be prevented since it is not possible to turn off this underlying validation mechanism of the browser.

Best regards,
Rumen
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Oscar
Top achievements
Rank 1
answered on 20 Jul 2018, 02:10 PM
Ah! Understood. Thanks a lot for the support!
Tags
Editor
Asked by
Oscar
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Oscar
Top achievements
Rank 1
Share this question
or