How to open a Form as a modal dialog in SharePoint 2010
KB001348
PRODUCT
This Knowledge Base article describes how to configure a SharePoint Page to open a Form as a modal dialog in SharePoint 2010/2013 and then close the modal dialog using another SharePoint Page and Rule created on the SmartForm.
Follow the steps below to implement the Form as a modal dialog in SharePoint
- Create the form you want to display in SmartForms (a basic sample form shown below)
- After saving the Form, note the Runtime URL used to access the Form:
- Prepare the script that you will add to SharePoint. Use a text editor tool and copy the sample code below, and replace the values in square brackets with appropriate values for your requirement and environment. For further information on this javascript method refer to http://msdn.microsoft.com/en-us/library/ff410058.aspx //SharePoint 2010
<a onclick="javascript:
var options = SP.UI.$create_DialogOptions();
options.url = '[URL]'
options.width = [Dialog Width];
options.height = [Dialog Height];
options.title = '[Dialog Title]';
SP.UI.ModalDialog.showModalDialog(options);" href="javascript://">
[Link Display Value]
</a>//SharePoint 2013
<a onclick="javascript:
var options = {
url: '[URL]',
width: '[Dialog Width]',
height: '[Dialog Height]',
title: '[Dialog Title]'};
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);" href="javascript://">
[Link Display Value]
</a>Value Description Example [URL] The URL of the SmartForm noted previously. http://DLX:81/Runtime/Runtime/Form/Hello+World+Form/ [Dialog Width] Set an appropriate width for the popup in pixels 640 [Dialog Height] Set an appropriate height for the popup. 480 [Dialog Title] The title displayed on the dialog window. Hello World Dialog Title! [Link Display] The text displayed to the user for the link. Hello World Link Display!
- On the SharePoint page where you want to load the SmartForm as a modal dialog. Edit the Page and insert a new Form > HTML Form Web Part as shown below:
- Edit the Web Part:
- On the ribbon, go to the Editing Tools > Form Content Editor > Source Editor menu option.
- In the HTML Source window paste the script previously mentioned. Click Save and then save the Page.
- A new Web Part will now appear on the screen:
- Click on the link and a popup modal dialog will appear:
- Create a new SharePoint Web Part Page or Wiki page within the SharePoint site. In this example, we created one under http://portal.denallix.com/SitePages/ClosePopup.aspx
- View the Page and edit the Page.
- Add a Form > HTML Form Web Part to the Page
- Edit the HTML Form Web Part and click on the Source Editor button
- Replace the existing source with the following code:
<script>window.frameElement.commonModalDialogClose(1, 'Close');</script>
- Click Save.
- Edit the SmartForm that is loaded in the popup in the K2 Designer.
- Add a Button control to the Form and rename the control to Submit.
- Go to the Rules and add the following Rule:
- Click configure to set up the rule action and specify the ClosePopUp.aspx page URL that you created above
- Click OK.
- Finish the Rule and the Form.
- Go to the SharePoint Page where the Hello World dialog link resides. Click on the link.
- The popup dialog opens as before.
- Now click on the Submit button and you should see that the dialog box closed.