Tuesday 24 May 2016

SharePoint apps - Iframe issue and form Save button issue

It is very common for us to try and connect to a default SharePoint page (ex, newform.aspx, editform.aspx) from an app, be it SharePoint/Provider hosted.
I had an Azure hosted app and there is a link in the app page to open the 'New Form' of a custom list. When we click on the link, nothing happens, the form doesnt open in a pop-up.
This is mainly because 'Framing' has been disabled by default. To resolve this, add the below piece of code in your masterpage/page layout

<WebPartPages:AllowFraming runat="server"/>

At this point you should be able to open up the default 'SharePoint pages' as pop-ups from an app.

There was another problem I faced once the new form had opened up. I was unable to hit the 'Save' button after filling the form. This is because the form is unsure which the parent window is, as the app redirection url doesnt have the SharePoint site's url. I was able to solve this by using the below code.
Add it in your 'newform.aspx' page either in a content editor or a script web part.

function PreSaveAction()
{
parent.window.location.href = document.referrer;
return true;
}

Now you should be able to submit default forms from an app!

No comments:

Post a Comment