0

I have a page that opens a dialog for a NewForm.aspx for a list. The code:

<script>
function openDialog(pageUrl) {
  var options = {
    url: pageUrl,
    title: 'Add Skills',
    allowMaximize: false,
    showClose: true,
    width: 500,
    height: 500
    //dialogReturnValueCallback: RefreshOnDialogClose   //when I try to use this line dialog  won't open.
};
  SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}

</script>
<a href="#" onclick="openDialog('http://london/lists/childribbon/newform.aspx');">Add New Item</a>

The script without the dialogReturnValueCallback works fine and it shows the dialog, but when I try to add dialogReturnValueCallback nothing happens.

thanks

6

The dialogReturnValueCallback should be used to get value back to your parent when click OK or Cancel.

So to can use dialogReturnValueCallback you should excute a function rather than set value as you do above to be like the following example

//Dialog Opening
function OpenDialog() {
    var options = SP.UI.$create_DialogOptions();
    options.url = 'http://london/lists/childribbon/newform.aspx';
    options.width = 500;
    options.height = 400;
    options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
    SP.UI.ModalDialog.showModalDialog(options);
}

Regarding the CloseCallback

// Dialog callback
function CloseCallback(result, target) {
    if (result == SP.UI.DialogResult.OK) {
        // Run OK Code
        // reload your page again
    }
    if (result == SP.UI.DialogResult.cancel) {
        // Run Cancel Code
    }
}

For more details check

1
  • Thank you my brother thank you so much, you are a live saver. God bless you. Sep 2 '16 at 7:23
4

Likely your RefreshOnDialogClose can't be referenced.

Have you checked your browsers console?

This happens when I'm correct:

enter image description here

Following snippet works if you get all required JS frameworks (sp.js, sp.ui.dialog.js)

    var body = document.createElement('div');
    body.innerHTML = 'Hello World';
    var dialog = SP.UI.ModalDialog.showModalDialog({
        title: "Hello World",
        html: body,
        dialogReturnValueCallback: function (dialogResult, result) {
            alert('hello world!');
            debugger;
        }
    });
0

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.