Problem with focus and radeditor

7 posts, 0 answers
  1. ericc34
    ericc34 avatar
    91 posts
    Member since:
    Jul 2006

    Posted 09 Sep 2011 Link to this post

    I have a asp.net page in which i have a panel. In this panel, i load controls (text box) dynamically. And under this panel I have a radeditor. When user change an textbox field, i change content of my radeditor like this :

    function ChangeTextEditorFieldValue(sender, args) {
    v
    ar elem = sender.get_element();

     

    var attributedElem = document.getElementById(elem.id + '_text');

     

    var fieldName = attributedElem.getAttribute('fieldCode');

    var oldValue = args.get_oldValue();
    var newValue = args.get_newValue();

    var editor = GetFormEditor();

    if (!oldValue) {
      var newhtml = ReplaceAll(editor.get_html(true), "{" + fieldName + "}", "[" + newValue + "]");
      editor.set_html(newhtml);
    ...

    When i do this, RadEditor got focus but I want to set focus to ELEM (textbox i've change) like this :

    elem.focus();

    but focus stay on radeditor. Why ??? I'm on IE9

  2. Rumen
    Admin
    Rumen avatar
    12849 posts

    Posted 13 Sep 2011 Link to this post

    Hi Ericc34,

    The set_html() method sets the focus in RadEditor to set the content.

    You can try two different approaches to fix the problem:

    1) Set the content in RadEditor using
        
         editor.get_document().body.innerHTML = newhtml;

    2) or set the focus on the textbox after a small delay, e.g.

    editor.set_html(newhtml);
    setTimeout(function()
    {
       elem.focus();
    }, 100);

    Kind regards,
    Rumen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ericc34
    ericc34 avatar
    91 posts
    Member since:
    Jul 2006

    Posted 26 Sep 2011 Link to this post

    Theses 2 solutions don't work, in first solution, all the document (page) are set to newhtml not only radeditor content and in second solution, radeditor keep focus
  5. JT
    JT avatar
    49 posts
    Member since:
    Mar 2007

    Posted 29 Nov 2011 Link to this post

    Same here. The first option does work, but the content in the editor doesn't refresh. So while I can verify the change was made by calling alert(editor.get_document().body.innerHtml); at the end of my javascript call, that doesn't help me much if the user can't see the change.

    And similarly, the timeout/focus option does not change the focus from the editor either.

    Is there no way to hand focus back after you've updated the content? I'm not sure I understand why we have to jump through hoops to get the focus back.

    Thanks!
  6. JT
    JT avatar
    49 posts
    Member since:
    Mar 2007

    Posted 29 Nov 2011 Link to this post

    Argh - I spoke too soon!

    The editor.get_document().body.innerHTML = newhtml; method works perfectly. Provided you use innerHTML, not innerHtml :-)

    I still think we shouldn't have to jump through the hoops, but at least it's an easy workaround ;-)

    Thanks Rumen!
  7. Chad
    Chad avatar
    8 posts
    Member since:
    Feb 2014

    Posted 14 May 2014 Link to this post

    How do I do this with JavaScript / JQuery?
  8. Ianko
    Admin
    Ianko avatar
    1535 posts

    Posted 15 May 2014 Link to this post

    Hello Chad,

    The discussed matter in this forum thread is entirely about client-side approaches and the mentioned editor.get_document().body.innerHTML = newhtml; line of code is written with JavaScript.

    Regards,
    Ianko
    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.

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