setfocus on content area

6 posts, 0 answers
  1. geetha priya
    geetha priya avatar
    25 posts
    Member since:
    May 2010

    Posted 22 Nov 2010 Link to this post

    Hi

    How to give set focus to the content area of the radeditor?
    the setfocus method is working in ie but not in chrome.
    if i gave the setFocus() it focus on the toolbar(like bold,italic) . not in the content area of editor.
    How to give the focus to content area?


    thanks in advance. 
    geetha.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Nov 2010 Link to this post

    Hello Geetha,


    I assume you have already referred the documentation. Give a try with following client code and see whether it help.
    Code:
    function SetFocusOnRadEditor() {
        var editor = $find("<%=RadEditor1.ClientID%>"); //get a reference to RadEditor client object
        editor.get_contentArea().focus();
    }



    -Shinu.
  3. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 23 Nov 2010 Link to this post

    Hi guys,

    The discussed approach would work but there is even an easier one - by using the special public method called setFocus which the editor exposes as shown below: 


    <form id="form1" runat="server">   
        <asp:ScriptManager ID="ScriptManager" runat="server" />  
        <telerik:RadEditor runat="server" ID="RadEditor1" OnClientLoad="OnClientLoad">   
            <Content>  
               Here is sample content!   
            </Content>  
        </telerik:RadEditor>  
        
        <script type="text/javascript">   
       function OnClientLoad(sender, args)   
       {   
          //set the focus on the the editor   
          setTimeout(function(){sender.setFocus();}, 0);    
       }   
           
        </script>  
        
        </form>  


    Kind regards,
    Svetlina
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  4. Jesper Vognsen Laustsen
    Jesper Vognsen Laustsen avatar
    7 posts
    Member since:
    Apr 2010

    Posted 22 Jan 2013 Link to this post

    None of the above helped med actually :-|

    I have a RadTextBox before the editor, and want to focus on editor contentarea (blinking cursor) when I tab out of the RadTextBox. 

    I have added a keydown event on the radtextbox, and let it call this function:

    function keydown(e) {
                var c = e.keyCode;
                if (c == 9) {
                    var editor = $find("<%=radMailBody.ClientID%>");
                    editor.get_contentArea().focus(); //Doesnt work! :-|
                    //editor.setFocus(); //Doesnt work :-(
                }
            }

    The event is fired, and this function is hit, I know it evaluates the if condition - tested with alert inside if statement. However the attempts to set focus on editor content area fails :-(

    It is a .net 2.0 application with Telerik.Web.UI version 2011.1.315.40.

    Any help is apprechiated, thanks.

    Sincerely,

    Jesper Laustsen
  5. Rumen
    Admin
    Rumen avatar
    14098 posts

    Posted 23 Jan 2013 Link to this post

    Hi,

    Try the following solution:
    <telerik:RadTextBox ID="RadTextBox1" ClientEvents-OnKeyPress="keydown" runat="server"></telerik:RadTextBox>
    <telerik:RadEditor OnClientLoad="OnClientLoad" runat="server" ID="radMailBody">
        <ImageManager ViewPaths="~/Images" UploadPaths="~/Images" />
    </telerik:RadEditor>
     
    <script>
        function OnClientLoad(editor) {
            var buttonsHolder = $get(editor.get_id() + "Top"); //get a reference to the top toolbar zone of the editor         
            var buttons = buttonsHolder.getElementsByTagName("A"); //get a reference to all A elements on the toolbar and disable the tabbing trough them         
            for (var i = 0; i < buttons.length; i++) {
                var a = buttons[i];
                a.tabIndex = -1;
                a.tabStop = false;
            }
        }
        function keydown(e) {
            var c = e.keyCode;
            if (c == 9) {
                var editor = $find("<%=radMailBody.ClientID%>");
                editor.setFocus(); //Doesnt work! :-|
                $telerik.cancelRawEvent(e);
        }
    }
     
    </script>


    Kind regards,
    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.
  6. Jesper Vognsen Laustsen
    Jesper Vognsen Laustsen avatar
    7 posts
    Member since:
    Apr 2010

    Posted 23 Jan 2013 Link to this post

    YES!!... thank you very much. It works. :-)

    /Jesper
Back to Top