Page 1 of 1

Redirect / Close all Dialogs after deleting item

Posted: 02 Sep 2020
by ragesoft
Hi,

i have following problem:

i open a normal "SP.UI.ModalDialog.showModalDialog" with de default "Display" form of an item ("Dialog1" for example)
Inside this dialog there is a button to open the Edit-Form in a new dialog ("Dialog2"):

Code: Select all

	SP.UI.ModalDialog.showModalDialog(   
     {  
       url: formUrl,
	   title: "Edit item",
	   dialogReturnValueCallback: closeContactDialog,
	 });
...	 
function closeContactDialog(){
	 SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel,"Close dialog");
}
This "formUrl" is pointing to the SPForm "Edit" and user can edit the item.
The "formUrl" contains the "Source" parameter to redirect user to current page (top-window) (if i dont provide this, user is redirected to the items list if deleting an item).

All fine.
"Close", "Cancel", "Save" => all working correct and closing all modal dialogs ("Dialog1" and "Dialog2").

If the user hit the "Delete Item" button in Ribbon, the spform is closing, but "Dialog2" and "Dialog1" are still open, but "Dialog2" is now empty.
How can i catch the delete event and close all dialogs after successfull deleted item...

Thx a lot!

Re: Redirect / Close all Dialogs after deleting item

Posted: 03 Sep 2020
by mnikitina
Hello ragesoft,

You can use this code to detect when the Delete button in the ribbon is clicked:

Code: Select all

var button = $( "a[aria-describedby='Ribbon.ListForm.Edit.Actions.DeleteItem_ToolTip']" );
$(button[0]).on('click', function() {
    console.log(true)
})

Re: Redirect / Close all Dialogs after deleting item

Posted: 04 Sep 2020
by ragesoft
Sounds good, but if the user clicks "cancel" in the dialgo "Would you like to delete the item" from sharepoint, it also fires.
How can i get the result of this action?

Thx :)

Re: Redirect / Close all Dialogs after deleting item

Posted: 08 Sep 2020
by mnikitina
Hello ragesoft,

I apologize for my late reply.

Looks like it is not possible to get the output of the confirmation box.

You can create a custom delete button using the code from this post and run your code when the item is deleted.