1

So I found the below code, from the below link, which allows SharePoint calendar events to be opened in a modal pop-up view rather than loaded into a new page, but would it be possible to tweak the code so that the pop-up opens into Edit mode by default so the user wouldn't have to manually click into Edit for the pop-up to make edits to the event? I am total noob with JavaScript and code in general.

https://social.msdn.microsoft.com/Forums/lync/en-US/e3c3aa6b-fb12-47d7-a64d-9985bf6a41e5/sharepoint-2013-calendar-overlay-open-in-the-model-popup?forum=sharepointdevelopment

<script src=http://code.jquery.com/jquery-1.11.1.min.js type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
    setInterval(function () {
        $("a[href*='DispForm.aspx']").each(function () {
            $(this).attr("onclick", "openDialog('" + $(this).text() + "','" + $(this).attr("href") + "')");
            $(this).attr("href", "javascript:void(0)");
            $(this).removeAttr("target");
        });
    }, 900);
});

function openDialog(title, url) {
    var options = {
        title: "Calendar - " + title,

    autoSize:true,
        url: url
    };
    SP.UI.ModalDialog.showModalDialog(options);
}
</script>

1 Answer 1

0

Use below code to open the edit form in dialog:

<script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        setInterval(function () {
            $("a[href*='DispForm.aspx']").each(function () {
                $(this).attr("onclick", "openDialog('" + $(this).text() + "','" + $(this).attr("href").replace('DispForm.aspx', 'EditForm.aspx') + "')");
                $(this).attr("href", "javascript:void(0)");
                $(this).removeAttr("target");
            });
        }, 900);
    });

    function openDialog(title, url) {
        var options = {
            title: "Calendar - " + title,

        autoSize:true,
            url: url
        };
        SP.UI.ModalDialog.showModalDialog(options);
    }
</script>
5
  • Thanks for the response! So the event opens directly into Edit mode, which is great! But, I do get a Web Part Error within the edit window (see below link for image): Web Part Error: Unknown server tag. Correlation ID: 0ce82ca0-477c-c013-39cb-500b5c84bafa. ibb.co/0K7gQ2j
    – Hank
    Mar 24, 2022 at 14:33
  • It is working fine at my end, I don't get any errors while using this code. Can you add the screenshot of error to your original question? Link in your above comment is not working. Mar 24, 2022 at 14:40
  • Ahh, you know what? I am getting this Web Part Error even without adding your modified code. So your code definitely works well for me, I am just not sure why I am getting the Web Part Error. I am getting the web part error after manually go into Edit mode WITHOUT your code. So something is weird. Would you try this link? ibb.co/0K7gQ2j
    – Hank
    Mar 24, 2022 at 14:58
  • I have marked your answer as the solution. I still dont know why I have the Web Part Error while in Edit mode though. As a bonus question, is there a way to tweak the code so that Saving an Edit to an event refreshes the webpart or sharepoint page? It's weird to save a change and not see it reflected on the calendar.
    – Hank
    Mar 24, 2022 at 14:59
  • Still not able to see the image using link given in above comments. Mar 24, 2022 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.