0

Does anyone have the javascript required to display the defaulteditform in the modal dialogue that SharePoint (v2010) displays an edit form in ? I'd like to add this to my html ?

0

In my answer I assume you use SP 2013 (see the path including '15'). So if you define the format function for the String object as (see source here):

String.format = (function () {
    // The string containing the format items (e.g. "{0}")
    // will and always has to be the first argument.
    var theString = arguments[0];

    // start with the second argument (i = 1)
    for (var i = 1; i < arguments.length; i++) {
        // "gm" = RegEx options for Global search (more than one instance)
        // and for Multiline search
        var regEx = new RegExp("\\{" + (i - 1) + "\\}", "gm");
        theString = theString.replace(regEx, arguments[i]);
    }

    return theString;
});

You can get the HTML for the link as:

function getLinkHtml(baseUrl, listId, itemId, title) {
    var result = String.format("<a title='Edit' class='editLink' onclick='OpenPopUpPageWithTitle(&quot;{0}/_layouts/15/listform.aspx?PageType=6&ListId=%7B{1}%7D&ID={2}&quot;, RefreshOnDialogClose, 1024,800,&quot;{3}&quot;);return false;' href='javascript:;'>Edit item</a>",
        baseUrl,
        listId.toUpperCase().replace(/-/g, '%2D'),
        itemId,
        title);

    return result;
}

The parameters are the base url (the url of your web), id of the list (guid), id of the list item (integer), and the title of the modal dialog window.

If you would like to insert the script that displays the edit modal dialog manually into an existing HTML-layout, it schould be something like (edit a fix item of a fix list):

onclick='OpenPopUpPageWithTitle("http://yourserver/yourweb/_layouts/15/listform.aspx?PageType=6&ListId=%7B3003B9A9%2D32E6%2D4FF0%2DB408%2DF5666A1643FD%7D&ID=3", RefreshOnDialogClose, 1024,800,"Edit this item");return false;'

In case of SP 2010 the only difference should be the URL. You don't need the folder 15 in that:

function getLinkHtml(baseUrl, listId, itemId, title) {
    var result = String.format("<a title='Edit' class='editLink' onclick='OpenPopUpPageWithTitle(&quot;{0}/_layouts/listform.aspx?PageType=6&ListId=%7B{1}%7D&ID={2}&quot;, RefreshOnDialogClose, 1024,800,&quot;{3}&quot;);return false;' href='javascript:;'>Edit item</a>",
        baseUrl,
        listId.toUpperCase().replace(/-/g, '%2D'),
        itemId,
        title);

    return result;
}

or for the simple onclick attribute (don't forget to update the link with the encoded Id of the list, and with the Id of yout item!):

 onclick='OpenPopUpPageWithTitle("http://yourserver/yourweb/_layouts/listform.aspx?PageType=6&ListId=%7B3003B9A9%2D32E6%2D4FF0%2DB408%2DF5666A1643FD%7D&ID=3", RefreshOnDialogClose, 1024,800,"Edit this item");return false;'
  • Hi. Many thanks for your response. I've checked the version being used. We are using SharePoint Server 2010. Does anyone have an example that would work with this version ? – JMR Feb 23 '15 at 13:53
  • Hi. Once again many thanks for your answer. Do you have sample HTML showing which js files I need to include and how to include these. I'm assuming that OpenPopUpPageWithTitle is defined in a js file under _layouts ? But I can't view this directory on our SharePoint server. – JMR Feb 24 '15 at 18:06
  • The _layouts folder corresponds in a typical installation to the path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS". The OpenPopUpPageWithTitle method is defined in the CORE.JS. This script is automatically included in all standard SP pages. – pholpar Feb 25 '15 at 6:46

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.