문제

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>
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top