1

I have a publishing page with a button users can click to launch a new list item form in a modal pop-up. It works great but I'm trying to add a page refresh after they click Save so they can see their posting and not end up re-submitting it. If they close it without saving the page should not refresh.

Here's what I've put together so far. It opens the form and posts the new list item just fine. It's only the page refresh that's not working. What am I missing?

<script>
var formOptions(pageUrl) = {
    url: pageUrl,
    title: 'Post New Classified',
    allowMaximize: false,
    showClose: true,
    dialogReturnValueCallback: function(result){
        if (result == SP.UI.DialogResult.Save) {
             SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.Save);
        }
        if (result == SP.UI.DialogResult.cancel) {
            //do nothing, modal was closed
        }
    }

  };    
   SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', formOptions);
</script>

<p align="center">
    <a href="#" class="btn btn-primary" role="button" target="_self" data-toggle="tooltip" data-placement="bottom" title="Post a New Classified" style="font-weight: bold; color: #ffffff !important;" onclick="openDialog('https://mysite.sharepoint.com/testing/Lists/Classifieds/NewForm.aspx');">Post a New Classified</a>
</p>
2

Try to use window.location.reload(); in the IF condition to refresh the page

Example

dialogReturnValueCallback: function(result){
        if (result == SP.UI.DialogResult.Ok) {
            window.location.reload();
        }
        if (result == SP.UI.DialogResult.cancel) {
            //do nothing, modal was closed
        }
    }

Also, this should work

dialogReturnValueCallback: function(result){
        if (result == SP.UI.DialogResult.Ok) {
            SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
        }
        if (result == SP.UI.DialogResult.cancel) {
            //do nothing, modal was closed
        }
    }

Check also Open a Link Via Modal Dialog In SharePoint.

  • I debugged and located a conflicting function using the same name in custom JS loaded in the page templates. I renamed the function and added your code and now it works perfectly. Thanks! – mojoriesen Aug 22 '18 at 19:00

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.