3

I've developed a ribbon button to Sharepoint inside Media tab. This opens a dialog where I list loads of content. On click I'm calling a function to close the dialog and it is supposed to insert some html into the editor.

....

options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
SP.UI.ModalDialog.showModalDialog(options);
}

.... this is the function that I'm returning

function CloseCallback(result, target) {
    ExecuteOrDelayUntilScriptLoaded(RTEActions, "sp.ui.rte.js");
}

function RTEActions() {
    RTE.Cursor.update();
    var html = 'testing';
    var rawRange = RTE.Selection.getSelectionRange().$C;
    RTE.DomHelper.pasteHtmlIntoRange(rawRange, html);
}

This is throwing an error: rawRange is undefined. Is there a better way to insert content into the editor?

2

Try this instead:

function RTEActions() {
    RTE.Cursor.update();
    var html = 'testing';
    RTE.Selection.getSelectionRange().pasteHtml(html);
}

A word of warning - this only works properly if the cursor is inside the RTE when the function runs - otherwise "testing" is inserted at the top of the page above everything else.

  • I'm running the function from the modal dialog that is shown after I click on a Ribbon control. Removing rawRange caused an error: rawRange.extractContents is not a function. If you click on "Link" button, it popups a window, you type whatever link you need, click OK and it puts the html on the editor. That's actually what I want but can't find a way for this to work – nhenrique Sep 4 '13 at 14:35
  • If you specify a function as the value for "dialogReturnValueCallback" then it runs in the context of the main page, NOT the dialog... – Chloraphil Sep 4 '13 at 14:41
  • the it should work right? Because I want to paste the content on the main page...the dialog it's just to return that content. And "dialogReturnValueCallback" is specified as a function, that's where I'm running RETActions() – nhenrique Sep 4 '13 at 14:46
  • 1
    Just to clarify, i didn't just remove the the third line of function RTEActions, I removed lines 3 and 4 and replaced them with a different line. Also, my code is tested and works on my page. – Chloraphil Sep 4 '13 at 15:06
  • That's it! It was my fault! You code works perfectly and it's just what I needed. Sorry about that confusion and thank you :) – nhenrique Sep 4 '13 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.