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

RadEditor keypress event

1 Answer 281 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 09 Nov 2010, 10:09 AM

I need to create a Javascript that does the following:

  1. Detect when the first key is pressed in the RadEditor

  2. Locate the cursor

  3. Programatically insert a piece of text where the cursor is

  4. Allow the normal process to continue, ie the key pressed by the user is to be added immediately after where I added the text.

I managed to do this for non-telerik normal text areas.  But it is giving me big problems with telerik RadEditor.Net2.dll version 7.2.0.0

On clientload of rad editor I am adding a KeyPress event handler.  However, in keypress method I am unable to get the cursor position.  I am using this script:

 

function getCaret(editor) {

if (editor.selectionStart) {

return editor.selectionStart;

}

else if (!document.selection) {

return 0;

}

var c = "\001";

var sel = document.selection.createRange();

var dul = sel.duplicate();

var len = 0;

dul.moveToElementText(editor); <-- GIVES JAVASCRIPT EXCEPTION OVER HERE

sel.text = c;

len = dul.text.indexOf(c);

sel.moveStart('character', -1);

sel.text = "";

return len;

}

What do you recommend?  Am I approaching this incorrectly for RadEditor?  I really need to get this working!

 

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 10 Nov 2010, 04:50 PM
Hi Daniel,

The content area of RadEditor is not a textbox but an editable IFRAME, but you should not experience problems to implement your scenario using the information below:

//You can get a reference to the editor object like this:
var editor = GetRadEditor('<%=RadEditor1.ClientID%>');

//You can get a reference to the document object in the editor content area like this:
editor.Document – reference document object in the content area

//You can create a range in IE like this:
editor.Document.selection.createRange();

See the following forum thread which could be helpful: http://www.telerik.com/community/forums/aspnet/editor/drag-and-drop-cursor.aspx.


Sincerely yours,
Rumen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Editor
Asked by
Daniel
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or