Prevous sibling node when i press enter on the H! tag data

2 posts, 0 answers
  1. Neha
    Neha  avatar
    18 posts
    Member since:
    Feb 2014

    Posted 16 Aug 2014 Link to this post

    Hello ,

    I have to find the previous sibling of the element when I press enter of the text .

     For example
    <h1>Telerik editor Text</h1>

    when i press enter in the H1 tag in between the this text "Telerik editor Text" then the editor we create two H1 tag either of adding br tag in between so for that I want the element before the cursor position.

    For example : in between in this I have a cursor at this text "Telerik editor Text" at the "tele |"cursor position" so i want the "tele" element .
    I have used the getselectionhtml but it return null value
  2. Nikolay
    Admin
    Nikolay avatar
    64 posts

    Posted 20 Aug 2014 Link to this post

    Hi,

    You can set the RadEditor's NewLineMode property to"Br" to insert BR elements instead of adding new block elements.

    If you need to add BR elements only in headings, you can change the NewLIneMode only for headings.  See the code below.
    <telerik:RadEditor ID="RadEditor1" runat="server" NewLineMode="P"
        OnClientCommandExecuted="OnClientCommandExecuted"
        OnClientCommandExecuting="OnClientCommandExecuting">
        <Content>
            <h1>Some heading</h1>
            <p>some paragraph</p>
        </Content>
    </telerik:RadEditor>
     
    <script>
        function OnClientCommandExecuting(editor, args) {
            if (args.get_commandName() == "EnterNewLine") {
                var selectedElement = editor.getSelectedElement();
                if (Telerik.Web.UI.Editor.Utils.getElementParentByRegExpTagName(selectedElement, /^H[1-6]$/i)) {
                    editor.set_newLineMode(Telerik.Web.UI.EditorNewLineModes.Br);
                }
            }
        }
     
        function OnClientCommandExecuted(editor, args) {
            if (args.get_commandName() == "EnterNewLine") {
                editor.set_newLineMode(Telerik.Web.UI.EditorNewLineModes.P);
            }
        }
    </script>


    Here is how you can get the previous element by handling OnClientCommandExecuted event.
    <script>
        function OnClientCommandExecuted(editor, args) {
            if (args.get_commandName() == "EnterNewLine") {
                var selectedElement = editor.getSelectedElement();
                var selectedHeading = Telerik.Web.UI.Editor.Utils.getElementParentByRegExpTagName(selectedElement, /^H[1-6]$/i);
                if (selectedHeading) {
                    var previous = $telerik.$(selectedHeading).prev().get(0);
                }
            }
        }
    </script>

    If this does not help, could you explain in more details what you are trying to achieve?

    Regards,
    Nikolay
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top