Thursday, January 9, 2014

SharePoint - Add button Apply to List Item Edit Form for Saving Item without closing form

This post describes how to create an Apply button in list item edit form, to save data and reload form, without redirect to list (or Source).

Create a custom edit form with SharePoint Designer.
Open form in edit mode.

Create new parameter of type QueryString for Source, named Source: when page refresh after saving data, url maintains Source (i.e. for redirect to list when you click on Save or Cancel).

Then, search for this code

<xsl:param name="dvt_apos">&apos;</xsl:param>
<xsl:variable name="dvt_1_automode">0</xsl:variable>

And add code below:

<xsl:param name="ListItemId">0</xsl:param>
<xsl:param name="Source"></xsl:param>

Search for button save/cancel in xslt, find this code:

<SharePoint:SaveButton runat="server" ControlMode="Edit" id="savebutton2"/>

Add code below (the button):

<input type="button" value="Applica" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={ModificaPratica.aspx?ID=',$ListItemId,'&amp;Source=',$Source,'}'))}" />

In code, you see GeFireServerEvent function: this executes save and then redirect to url shown.
The url concatenates ID and ListItemId parameter and Source with correspondant parameter.

Result: when you click on Apply, Item is saved and page reload (with same Source in querystring), insthead of redirect to Source.

Tips: you can add new Custom Action to list item (with SPDesigner), adding call to js function that execute click on button with name="btnSave".


So, you have ribbon button for Apply (save and reload form), Save (save and close, redirect to source), Cancel (close and redirect to source)