Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to open the new item form in a modal dialog. The following code works perfectly when used in SharePoint-hosted app, but does for some reason not work in a script editor web part on a SharePoint page. My guess is that the script file doesn't load properly.

JavaScript
function openNewItemDialog() {

       var options = {
           url: appWebUrl + "/Lists/ListName/NewForm.aspx",
           width: 500,
           height: 500,
           title: "Form title"
       };
       SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}


I would appreciate som help.

Thanks
Posted
Updated 26-Nov-14 3:19am
v2
Comments
Pradip R 26-Nov-14 8:38am    
When I tried your above code, it gave me Unexpected token error. So I have changed the
"Form title" to "Form title" and it worked for me. Why don't you try that and let me know?
Member 11246293 26-Nov-14 9:28am    
Thank you for your reply.

I don't understand, it doesn't matter what I enter as title:"xxxx" as it is just displayed at the top of the dialog? Please explain.
Pradip R 26-Nov-14 9:32am    
I see the question has been updated. Have you tried debugging this click event? Also verify that whether the script has been loaded or not.
Member 11246293 26-Nov-14 9:39am    
I found the issue, I didn't pass appWebUrl correctly. Thanks Pradip R.

1 solution

I found the issue, I didn't pass appWebUrl correctly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900