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

Problem with focus and radeditor

6 Answers 143 Views
Editor
This is a migrated thread and some comments may be shown as answers.
ericc34
Top achievements
Rank 1
ericc34 asked on 10 Sep 2011, 03:06 AM
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

6 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 13 Sep 2011, 12:44 PM
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.
0
ericc34
Top achievements
Rank 1
answered on 26 Sep 2011, 01:49 PM
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
0
ATS
Top achievements
Rank 1
answered on 30 Nov 2011, 01:01 AM
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!
0
ATS
Top achievements
Rank 1
answered on 30 Nov 2011, 01:06 AM
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!
0
Chad
Top achievements
Rank 1
answered on 14 May 2014, 06:29 PM
How do I do this with JavaScript / JQuery?
0
Ianko
Telerik team
answered on 15 May 2014, 09:53 AM
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.

 
Tags
Editor
Asked by
ericc34
Top achievements
Rank 1
Answers by
Rumen
Telerik team
ericc34
Top achievements
Rank 1
ATS
Top achievements
Rank 1
Chad
Top achievements
Rank 1
Ianko
Telerik team
Share this question
or