Open SharePoint 2010/2013 Display, Edit, New Forms in Modal Dialogs
If you want to open a SP 2010 or in SP 2013 list item in a modal dialog you have two choices. Using the standard JavaScript functions or creating own functions.
If the dialog box appears you don't have an address bar to pick up the called URL. To see which URL is called when you edit or open a list item use the Internet Explorer Developer Tools.
Open your source list in the Internet Explorer. Press F12 to open the developer tools.
Click on the "Network" tab and then on "Start Capturing"
Now click the link you want to track.
You'll see the requests listed and you can also copy the urls for your need.
SharePoint usually calls the /_layout/listform.aspx with the list parameter. The form then redirects to the appropriate list form.
When using SharePoint 2010 core javascript functions to open elements in dialogs mostly you'll need to know :
<a target="_self" href="javascript:EditItem2(null, 'http://sharepoint/yoursite/_layouts/listform.aspx?PageType=4&ListId={60EDAB82-D9EF-4F89-BCEB-D9B287BDCC96}&ID=1&ContentTypeID=0x01020004D023775B015F43930EAF26E5B8AD35')">Urlaub in Jamaica</a>
<a target="_self" href="javascript:EditItem2(null, 'http://sharepoint/yoursite/_layouts/listform.aspx?PageType=6&ListId={60EDAB82-D9EF-4F89-BCEB-D9B287BDCC96}&ID=1&ContentTypeID=0x01020004D023775B015F43930EAF26E5B8AD35')">Urlaub in Jamaica</a>
<a href="javascript:NewItem2(null, ''http://sharepoint/yoursite/_layouts/listform.aspx?PageType=8&ListId={xxxxxxxxxx}&RootFolder=')">New Item</a>
You can use the SharePoint Dialog Framework to create your own dialog. You can also use the standard form template links:
Create a small javascript function which takes the url as parameter and place it somewhere in your file
Now you can call one of the forms with:
You can certainly adapt the function with e.g. the ID parameter of the item and so on...
How to find which item URL is called
If the dialog box appears you don't have an address bar to pick up the called URL. To see which URL is called when you edit or open a list item use the Internet Explorer Developer Tools.
Open your source list in the Internet Explorer. Press F12 to open the developer tools.
Click on the "Network" tab and then on "Start Capturing"
Now click the link you want to track.
You'll see the requests listed and you can also copy the urls for your need.
SharePoint usually calls the /_layout/listform.aspx with the list parameter. The form then redirects to the appropriate list form.
Method 1: Using core functions
- the ID of the list
- the ID of the Content Type
- the ID of the list item
- the Page Type
Display Item Dialog
PageType = 4 (Display Form)
Edit Item Dialog
PageType = 6 (Edit Form)
New Item Dialog
PageType = 8 (New Form)
<a href="javascript:NewItem2(null, ''http://sharepoint/yoursite/_layouts/listform.aspx?PageType=8&ListId={xxxxxxxxxx}&RootFolder=')">New Item</a>
Method 2: Using custom functions
You can use the SharePoint Dialog Framework to create your own dialog. You can also use the standard form template links:
- Display Form: http://sharepoint/sites/test/Lists/Kalender/DispForm.aspx?ID=1
- Edit Form: http://sharepoint/sites/test/Lists/Kalender/EditForm.aspx?ID=1
- New Form: http://sharepoint/sites/test/Lists/Kalender/NewForm.aspx
Create a small javascript function which takes the url as parameter and place it somewhere in your file
function openDialog( pUrl ) {
SP.UI.ModalDialog.showModalDialog(
{
url: pUrl,
width: 500,
height: 500,
title: "My Dialog"
}
);
}
Now you can call one of the forms with:
<a href="javascript:openDialog('http://sharepoint/sites/test/List/Kalender/DispForm.aspx?ID=1')">
Open Item
</a>
You can certainly adapt the function with e.g. the ID parameter of the item and so on...
function openCalendarDialog( pID ) {
SP.UI.ModalDialog.showModalDialog(
{
url: 'http://sharepoint/sites/test/List/Calendar/DispForm.aspx?ID='+pID,
width: 500,
height: 500,
title: "My Dialog"
}
);
}
The HTML to call the function would be:
<a href="javascript:openCalendarDialog(1)">
Open Event
</a>
Comments
I tried using xslt but it breaks the script.
Why do you want this to work in an html file ? Can you specify where do you want to use the js or html file. To use the SP modal dialog you have to reference all the SP JavaScript files.
Thanks
SP.UI.ModalDialog.showModalDialog(
{
url: "http://sharepoint/sites/test/Lists/Calender/DispForm.aspx?ID=" + pID,
width: 500,
height: 500,
title: "My Dialog"
}
);
}
Thanks for the blog post.
Any tweak we need to do with this to work on Sharepoint 2013?
Thanks!
SPbb
My list has Enhanced rich text column . when i try to edit this column in modal popup the Enhanced rich text ribbon controls eg. Insert hyperlink, upload images etc. throws page not found error.
Any idea..
it seems that your post is closely related to an issue I am having
Can you please give more insight about the following :
I have a sharepoint calendar whose display form I have added a jquery script to using the CEWP. When I click on an item on the calendar for display I get different behaviors
if I click the item within the same page, the script doesn't get executed and I get directed to this URL:
https://microsoft.sharepoint.com/teams/mysite123/_layouts/15/start.aspx#/Lists/ORB/DispForm.aspx?ID=15&Source=https%3A%2F%2Fmicrosoft%2Esharepoint%2Ecom%2Fteams%2FORBMEA%2FSitePages%2FORB%2520Request%2Easpx
When I right click and choose open in a new tab the script works and I get directly here: https://microsoft.sharepoint.com/teams/mysite123/Lists/ORB/DispForm.aspx?ID=15
The script also works great when I double click the cell and it opens in a dialog form
Any pointers will be much appreciated