I'm using the following code to allow users to create a new discussion topic in a modal dialog, rather than on a new page:
// When called, this function opens the dialog.
function openDialog(pUrl) {
var options = {
url : pUrl };
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}
// When called, this function opens the new or existing discussion in a modal dialog instead of on a new page.
function clickMe() {
$('a[href*="NewForm.aspx"]').each(function() {
$(this).attr('onclick', 'openDialog("' + $(this).attr('href') + '")');
$(this).attr('href','javascript:void(0)');
});
$('a[href*="Forum.aspx"]').each(function() {
$(this).attr('onclick', 'openDialog("' + $(this).attr('href') + '")');
$(this).attr('href','javascript:void(0)');
});
}
window.onload = function () {
// Timeout in case the script doesn't load properly.
clickMe();
setTimeout(function() {
clickMe();
}, 500);
};
This works fine. When I click on "New discussion" it opens in a modal dialog and I can fill in a topic and a message, but when I click "OK" in the dialog the page does not automatically refreshes. If I manually refresh the page, I can see my new discussion. But I want it to refresh automatically whenever a new item is added.
How can I achieve this? Is there a setting for this or should I solve this with JavaScript (and if so, how?)?