DFFS: Creating a "delete" button on Edit form

Home Forums General discussion DFFS: Creating a "delete" button on Edit form

Tagged: , ,

Viewing 4 reply threads
  • Author
    Posts
    • #7694
      avala
      Participant

        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?

      • #7695
        Alexander Bautz
        Keymaster

          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

        • #7698
          avala
          Participant

            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?

          • #7699
            Alexander Bautz
            Keymaster

              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

            • #7700
              avala
              Participant

                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, 7 months ago by avala.
                • #7702
                  avala
                  Participant

                    Nope, that will only go back to the “refresh page” after submitting the new form.

                    Went with:

                    window.location.href="http://url";
              Viewing 4 reply threads
              • You must be logged in to reply to this topic.