Skip Navigation

[Resolved] How to show a warning before deletion of a post in a loop/view (table row)?

This support ticket is created 2 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 11 replies, has 2 voices.

Last updated by Pierre 2 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#2316331
view-with-delete.jpg
warning-before.jpg

Tell us what you are trying to do?
I have a button inserted (it's actually a form button that deletes the post in a particular row.
Now I want to show a confirmation notice before the post is being deleted.
How can I achieve this?

This is the delete button being used in that view
<div class="tabort">[cred-delete-post action='trash' onsuccess='self' class=' btn-sm btn-dark']<i class="fa fa-trash-o"> Ta bort[/cred-delete-post]</div>

#2316567

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pierre,

Thank you for getting in touch.

You will definitely need to use custom coding in order to do this. You will perhaps need to intercept the onclick event to add the warning before the item is deleted.

If you're familiar with Javascript then you can use the tutorial below to craft a solution for this.
hidden link

Please let know if this helps.
Thanks,
Shane

#2316621

Thanks for the tip Shane,
In my case, where do I put the script for this particular button (The JS section for that view?)?

Also. In the example code (

<input type="button" value="Delete" onclick="delete();" />

) they are referring to value="Delete", but in my shortcode it says: action='trash'.

[cred-delete-post action='trash' onsuccess='self' class=' btn-sm btn-dark']

. How to interpret this?

Thanks!

#2316675

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pierre,

Yes that is correct, it will be added to the JS section of the view.

My recommendation here is to add an additional class to the delete button class=' btn-sm btn-dark' such as "delete-notice"

Then you should be able to reference it by

var btn = jQuery(".delete-notice");

Also replace each instance of $ with jQuery.

<input type="button" value="Delete" onclick="delete();" />

This code can essentially be ignored because its an example of a button that would be on the page.

Please let me know if this helps.
Thanks,
Shane

#2317043

Thanks Shane,
I added the script and the warning dialog appears.
I thought everything was fine, but when I click "Cancel", the post is still being deleted?
See here: hidden link

The button widh included class (delete-notice):

[cred-delete-post action='trash' onsuccess='self' class=' btn-sm btn-dark delete-notice']

This is the code available in the JS-field for the view:

var btn = jQuery(".delete-notice");
btn.data("funcToCall", btn.attr("onclick"));
jQuery(".delete-notice").removeAttr("onclick");
jQuery(".delete-notice").bind("click", function(e){
    if(confirm("Are you sure you want to delete this row?")){
        var func = jQuery(this).data("funcToCall");
        eval(func);
    }
});
#2317395

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pierre,

You may need to look at the eventlisteners for this delete action button. Unfortunately I cannot check from my end since I dont have access to the site.

Can you provide this so that I can have a look to see what are the delete action listeners that are on this button? Perhaps its not as simple as an onclick action that is at play here.

Thanks,
Shane

#2317477

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pierre,

I spoke with another supporter on this to see if they were aware of the correct function to unbind.

Turns out that the shortcode supports confirmation messages. Given that this is an old shortcode then the documentation for it doesn't exist anymore. However try the following and let me know if it helps.

[cred_delete_post_link action="delete" text="Delete %TITLE%" message_after="Post deleted" message="Are you sure you want to delete this post?" message_show="1"]

Thanks,
Shane

#2317573
deleting.jpg

I see,
Well it almost work.
It does delete the post but only if I refresh the page manually.
This is what I use now:

[cred_delete_post_link action="delete" text="Ta bort" message_after="Post deleted" message="Är du säker på att du vill radera raden?" message_show="1" class="btn-sm btn-dark"]

.

You can try it out yourself as logged in.

#2317767

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pierre,

This is an old shortcode and is possibly deprecated given that the documentation for it doesn't exist.

Can you try adding this attribute to the shortcode as well message_after="deleted."
Let me know if this message shows after you've clicked on the delete button.

Apart from this my assistance here is quite limited since the new shortcode doesn't provide this functionality.

Thanks,
Shane

#2318067

Hi Shane,
That parameter was already included before, but said "Post deleted".
The message is shown in the dialogue box right after I have clicked OK. But in my table row, the text "deleting..." is still shown and the row is not deleted until I have refreshed the whole page.

Could it be possible to do some kind of workaround here with the js-script you sent me at the beginning of this thread?
I'm thinking that maybe it's possible to send a "refresh" right after the OK button has been clicked?

#2318789

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pierre,

You can bind the reload function to the button click so when the user clicks the delete button and confirms then it reloads the page.

hidden link

This should allow you to workaround the problem.
Thanks,
Shane

#2319171

My issue is resolved now.

I managed to solve this by using this delete button:

[cred-delete-post action='trash' onsuccess='self' class=' btn-sm btn-dark delete-notice']

Alert message script
I had to add else {return false;}, otherwise the post still got deleted even though I pressed Cancel in the alert window:

//Alert notice
var btn = jQuery(".delete-notice");
btn.data("funcToCall", btn.attr("onclick"));
jQuery(".delete-notice").removeAttr("onclick");
jQuery(".delete-notice").bind("click", function(e){
    if(confirm("Are you sure?")){
        var func = jQuery(this).data("funcToCall");
        eval(func);
    } else {
	    return false;
    }
});
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.