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

insertHtml...strange behaviour

2 Answers 171 Views
Editor
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
simone
Top achievements
Rank 1
simone asked on 14 May 2011, 02:52 PM
Hi everybody, in my project I'm notice a strange behaviour of the exec command insertHtml. This is my situation:
I have tWindow (created client side) with an editable (in-line) tGrid. Three of the tGrid columns being edited with tEditor, in the tEditor I've configured some snippets (that works always good) and some custom buttons that use insertHtml exec command to... insert html at the cursor position :).
One of this custom buttons before executing the insertHtml command opens a new modal tWindow (again created client side). This window has a tDropDownList to let the user to choose which html have to be inserted; when the window is closed I call the exec function of the tEditor to insert the selected value of the tDropDownList.
Now the strange behaviour is that if the user didn't open the tDropDownList but just close the modal tWindow, everything works good (for debug purpose I always add an html string). On the other side if the user open the tDropDownList , choose an element and then close the modal tWindow, the selected element is added on the top left of the editor (as first word) and not at the cursor position.
I call exec insertHtml in the "close" event of the tWindow. This is the js function that handle the click of the custom button and opens the modal tWindow:

function SetValueInEditorFromComplex(e, objTextarea, url, winTitle) {
 
    var lookupWindow;
    var evt = $.Event(e);
    evt.stopPropagation();
    evt.preventDefault();
 
 
    lookupWindow = $.telerik.window.create({
        name: "RuleSetGetAgeWindow",
        title: winTitle,
        contentUrl: url,
        modal: true,
        resizable: true,
        draggable: true,
        onClose: function (ev) {
 
            var hd = lookupWindow.find('#hdValue');
            var editor = $('#' + objTextarea).data('tEditor');
            editor.focus();
            if (hd && hd.val != '') {
                editor.exec('insertHtml', { value: 'Age(' + hd.val() + ')' });
            }
 
            lookupWindow.data('tWindow').destroy();
        }
    });
 
    lookupWindow
                .css({
                    left: window.mouseXPos + 50,
                    top: 5
                })
                .data('tWindow')
                .open();
 
    lookupWindow.focus();
}


Can someone please help me?
Thanks to all

2 Answers, 1 is accepted

Sort by
0
simone
Top achievements
Rank 1
answered on 17 May 2011, 08:51 AM
...nobody answer...I'm alone :(
I've found that if I use the "standard" DropDown (@(Html.DropDownList(...)) everything works good, so probably the problem raise when the focus is set on another Telerik element...
0
Vasile
Top achievements
Rank 1
answered on 05 Oct 2011, 10:00 PM
Hello,
I had the same problem spent some time on it- too much unfortunatelly, there is another thread on this topic
http://www.telerik.com/community/forums/aspnet-mvc/editor/inserting-text-at-the-current-cursor-position.aspx
suggesting a solution, but that did not work for me on IE 9 with 2011.2.914

Anyway I think I found something that works properly, I know some time passed since you asked for help, but this may help others having the same issue.
Solution is like this: before having the chance to open the DropDownList and mess the editor cursor, save the current range of the editor control, like this:
var editor = $(crossRefHostEditor).data('tEditor');
crossRefRange = editor.getRange();

then you show your modal window, you select whatever you want from the DropDownList and then when you are about to insert the html in the editor you just restore the range:
var editor = $(crossRefHostEditor).data('tEditor');
editor.focus();
editor.selectRange(crossRefRange);
editor.exec("insertHtml", { value: 'whatever html markup' });

works like a charm for me

regards,
Vasile M (wizardnet)

Tags
Editor
Asked by
simone
Top achievements
Rank 1
Answers by
simone
Top achievements
Rank 1
Vasile
Top achievements
Rank 1
Share this question
or