Editor Loses Focus With Custom Dialog

2 posts, 0 answers
  1. Dan Ehrmann
    Dan Ehrmann avatar
    166 posts
    Member since:
    Jul 2004

    Posted 10 Apr 2013 Link to this post

    I have several custom dialogs attached to toolbar buttons which do various things like insert links. Frequently (not always), when I call pasteHtml(), the content gets inserted at the top of the editor, rather than at the cursor position.

    I understand that this is due to the editor losing focus, and therefore forgetting the cursor position. You can sort-of reproduce this in the demo editor. Place the cursor in the middle of the content somewhere, then click on a blank area of the toolbar, so that the editor loses focus. Then click the add link button and see that the link gets inserted at the top.(I know this is artificial, but I think it a useful demonstration of what happens.)

    I am trying to figure out how to either prevent the loss of focus, or write some code which remembers the cursor position so that I can restore it before calling pasteHtml().

    I tried calling editor.getSelection().getRange() after the button click, but the focus seems to already be lost, and the range object seems to refer to the top of the editor content. I also tried calling getRange() in OnClientSelectionChange, and also in a 'blur' event I attached to the content area. I have tried to set unselectable="on" in various places. None of these things helped.

    I see that this behaves reliably in your built-in dialogs. So I wonder what I am doing wrong. (My custom dialogs are iframes contained in jQuery UI dialogs, which I don't think is too different in principle from your built-in dialogs.)
  2. Marin Bratanov
    Marin Bratanov avatar
    5707 posts

    Posted 15 Apr 2013 Link to this post

    Hello Dan,

    Are you following the approach for creating custom dialogs that is shown in this demo: http://demos.telerik.com/aspnet-ajax/editor/examples/customdialogs/defaultcs.aspx? I have tested it (including the customized insert link dialog) and it seems to function as expected. As you can see in the code custom dialogs rely on internal functionality in the control which is why they work with passing arguments.

    Kind regards,
    Marin Bratanov
    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.
Back to Top