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

setfocus on content area

5 Answers 212 Views
Editor
This is a migrated thread and some comments may be shown as answers.
geetha priya
Top achievements
Rank 1
geetha priya asked on 22 Nov 2010, 11:16 AM
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.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Nov 2010, 12:22 PM
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.
0
Svetlina Anati
Telerik team
answered on 23 Nov 2010, 03:52 PM
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.
0
Jesper Vognsen Laustsen
Top achievements
Rank 2
answered on 22 Jan 2013, 10:04 PM
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
0
Rumen
Telerik team
answered on 23 Jan 2013, 02:28 PM
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.
0
Jesper Vognsen Laustsen
Top achievements
Rank 2
answered on 23 Jan 2013, 08:36 PM
YES!!... thank you very much. It works. :-)

/Jesper
Tags
Editor
Asked by
geetha priya
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Svetlina Anati
Telerik team
Jesper Vognsen Laustsen
Top achievements
Rank 2
Rumen
Telerik team
Share this question
or