This is a migrated thread and some comments may be shown as answers.
New Line Repeating Class
3 Answers 21 Views
This is a migrated thread and some comments may be shown as answers.
Dan Ehrmann
Top achievements
Rank 1
Dan Ehrmann asked on 10 May 2012, 08:43 PM
I have a paragraph in the editor lie this (looking at html view):

    <p class="some-class">some text</p>

When the user presses 'Enter' to create a new line, the class is repeated:

    <p class="some-class">&nbsp;</p>

I would prefer that a new line create a <p> without the class - how can I make this happen?

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 15 May 2012, 06:08 AM
Hi,

Here is an example on how to strip the className attribute of the newly inserted paragraph:

    <head id="Head1" runat="server">
        <title></title>
        <style type="text/css">
            .first_p_only { background-color: Red; }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="Scriptmanager1" runat="server" />
            <script type="text/javascript">
                function OnClientCommandExecuted(editor, args) {
                    var command = args.get_commandName();
                    if (command == "EnterNewLine") {
     
                        if ($telerik.isIE) {
                            editor.get_contentWindow().setTimeout(function () {
                                var parent = editor.getSelection().getParentElement();
                                parent.className = "";
                                var selection = editor.getSelection();
                                selection.selectElement(parent);
                                selection.collapse(true);
                            }, 0);
                        }
                        else {
                            var parent = editor.getSelection().getParentElement();
             
                            parent.className = "";
                            var selection = editor.getSelection();
                            selection.selectElement(parent);
                            selection.collapse(true);
                        }
                    }
                }
            </script>
            <telerik:RadEditor runat="server"  OnClientCommandExecuted="OnClientCommandExecuted" NewLineMode="P"
                               ImageManager-ViewPaths="~/Images" ImageManager-UploadPaths="~/Images" ID="RadEditor1">
                <Content>
                    <p class="first_p_only">Only the first paragraph should be styled.</p>
                </Content>
            </telerik:RadEditor>
 
        </form>
    </body>
</html>


Greetings,
Rumen
the Telerik team
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 their blog feed now.
0
Dan Ehrmann
Top achievements
Rank 1
answered on 15 May 2012, 04:01 PM
Thanx Rumen - I will try this

is this browser behavior? or radeditor behavior?
0
Rumen
Telerik team
answered on 16 May 2012, 04:07 PM
Hello,

It is a browser behavior as you can see in the following test with editable iframe: http://screencast.com/t/D467IGeq.

All the best,
Rumen
the Telerik team
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 their blog feed now.
Asked by
Dan Ehrmann
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Dan Ehrmann
Top achievements
Rank 1
Share this question
or