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

[Solved] FormatCodeBlock - Set Focus On

1 Answer 120 Views
Editor
This is a migrated thread and some comments may be shown as answers.
carlpro
Top achievements
Rank 1
carlpro asked on 04 Apr 2008, 09:12 PM
When one clicks on the FormatCodeBlock icon in the RadEditor (Build 2007.2 - 1428), the FormatCodeBlock dialog comes up, but the source textbox does not have focus (one must click in that text box to set its focus).

How does one set the focus on that textbox when that dialog first comes up?

I've tried the following in the following in the "OnClientCommandExecuted" event handler, but no luck yet...

var codeFormatter = top.frames[1].document.getElementById('dialogControl_codeFormatter_dirtyCode');  
if (codeFormatter)  
{  
    codeFormatter.setFocus();  
}  
 

The first time through, it's not found. However, clicking the FormatCodeBlock again, then the control is found, but setFocus has no effect.

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 07 Apr 2008, 11:49 AM
Hi Carl,

Here is an example how to achieve your scenario:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<telerik:RadEditor ID="RadEditor1" OnClientCommandExecuted="OnClientCommandExecuted" Runat="server">
<Tools>
    <telerik:EditorToolGroup>
        <telerik:EditorTool Name="formatcodeblock" />
    </telerik:EditorToolGroup>
</Tools>
</telerik:RadEditor>
<script type="text/javascript">
function OnClientCommandExecuted(editor, args)
{
   if(args.get_commandName() == "FormatCodeBlock")
   {
       setTimeout(function()
       {
           var codeFormatter = top.frames[1].document.getElementById('dialogControl_codeFormatter_dirtyCode'); 
           //codeFormatter.style.border = "1px solid red";
           codeFormatter.focus();
       }, 1000);
   }
}
</script>


Best regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Editor
Asked by
carlpro
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or