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".

$("input[name='btnSave']").click();

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

Comments

Popular posts from this blog

Sharepoint 2010 - Filter List/Library Web Part with XSLT and Content Editor WP

Sharepoint 2010 - Multilanguage Site - Show column in current language

Sharepoint 2010 - Enable/Disable Ribbon Button with EcmaScript