4

In SP2010 you could easily show a dialog using a DOM node with something like this:

var test = "<div id='correspondence'>" + result + "</div>";
        $('body').append(test);

        SP.UI.ModalDialog.showModalDialog({
            html: document.getElementById('correspondence'),
            title: "Correspondence",
            allowMaximize: false,
            showClose: true,
            autoSize: true
        });

In SP 2013 I cannot for the life of me get this working. All that I get is an error stating: SyntaxError: missing ) after argument list. Below is the code I tried. Any ideas on how to get this working?

SP.SOD.executeFunc('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', function() 
{ 
    var dlgOptions = { html:document.getElementById('correspondence'), autoSize: true, autoSizeStartWidth: 550 };  
    SP.UI.ModalDialog.showModalDialog(dlgOptions); 
});                 

2 Answers 2

4

In the first code snippet you have doubled the ' around getElementById.

In the second code snippet you have forgotten the html: in front of getElementById

Edit after James comment: If you are not using minimal download strategy, you do not have to use SOD.

1
  • 1
    You need SOD when you have minimal download strategy turned on.
    – James
    Commented Aug 8, 2013 at 21:24
1

As Robert has said there are issues with the JavaScript.

However, I had problems as well and had to add the following code to the base of my page to load the appropriate SharePoint scripts. The Initialise Page is a JavaScript function which sets up the page.

ExecuteOrDelayUntilScriptLoaded(ITSP.TaskForm.InitialisePage, "sp.ui.dialog.js");
SP.SOD.executeFunc("sp.js", "SP.ClientContext", function(){});
2
  • It says ITSP.TaskForm.InitialisePage is undefined when I run that code. Where did you get that from?
    – James
    Commented Aug 8, 2013 at 21:19
  • Sorry this is just a javascript function which is called when the sp.ui.dialog.js is loaded. I use a function to initialise the page and setup various elements on the page. You could wrap your dialog code inside a function and then reference the replace ITSP.TaskForm.InitialisePage with your function.
    – Simon Doy
    Commented Aug 8, 2013 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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