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

Mx.
  • 3,323
  • 1
  • 20
  • 41
Nderon Hyseni
  • 1,793
  • 6
  • 35
  • 63

2 Answers2

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

Mohamed El-Qassas MVP
  • 45,382
  • 9
  • 53
  • 96
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;
        }
    });
Mx.
  • 3,323
  • 1
  • 20
  • 41