Home › Forums › General discussion › DFFS: Creating a "delete" button on Edit form
- This topic has 5 replies, 2 voices, and was last updated 9 years, 4 months ago by avala.
-
AuthorPosts
-
-
May 26, 2015 at 21:42 #7694
We’re using the redirect to the Edit form from the New form to utilize vLookup (https://spjsblog.com/2011/04/23/redirect-from-newform-to-dispform-or-editform/). We’ve now been asked to create a Delete button in the Edit form in case the user needs to cancel mid-process. Any thoughts on creating a delete button in the form?
-
May 26, 2015 at 21:49 #7695
If you cannot use the default delete button in the ribbon, you can use custom code like this (requires spjs-utility.js):
var dRes = spjs.utility.deleteItem({ "listName":_spPageContextInfo.pageListId, "id":GetUrlKeyValue("ID") }); alert(dRes.success);
Please note this example id for SP2010 or 2013 – for SP2007 you must change “_spPageContextInfo.pageListId” with the actual GUID of the current list.
Alexander
-
May 26, 2015 at 22:57 #7698
Thanks, Alexander. I was able to get the Delete function to work on a Header button, but I’m not Java savvy enough to combine it with a close form function. Any tips?
-
May 26, 2015 at 23:08 #7699
If you are in a dialog, use something like this:
function deleteMe(){ var dRes = spjs.utility.deleteItem({ "listName":_spPageContextInfo.pageListId, "id":GetUrlKeyValue("ID") }); if(dRes.success){ window.frameElement.commitPopup(); } }
Call “deleteMe” from your custom button.
Alexander
-
May 27, 2015 at 14:57 #7700
Thanks, Alexander. We’re not using dialogs for our forms, but your suggestion pointed me to the following solution. Essentially, we’re providing a unique Delete button on the edit form only after it was initially submitted to provide the user with the ability to cancel out of the process without leaving “duplicate” items in the list.
Place this in the CSS and JS section of the Edit form:
function deleteMe(){ var dRes = spjs.utility.deleteItem({ "listName":_spPageContextInfo.pageListId, "id":GetUrlKeyValue("ID") }); if(dRes.success){ history.back(-4) } }
Created a Header in the tab section with the following code:
<input onclick="deleteMe();return false;" type="button" value=" Delete Report"/>
Created two rules:
1. If the form is Saved, set Initially Submitted Field to Yes (Default No)
2. If Initially Submitted = Yes, Hide Header with Delete button.- This reply was modified 9 years, 4 months ago by avala.
-
May 27, 2015 at 15:12 #7702
Nope, that will only go back to the “refresh page” after submitting the new form.
Went with:
window.location.href="http://url";
-
-
AuthorPosts
- You must be logged in to reply to this topic.