Is there a right way to run javascript confirm() when Remove button is pressed ?
I tried the following but it won't bind the click event. Nothing happens.

Drupal.behaviors.mymoduleConfirmRemoval = function(context) {
  $('input.form-submit', context).bind('click', myconfirmFunc );

It, however, does bind with mousedown event but mousedown ignores my_confirm()'s return value.

Any insight would be appreciated.


drudrew’s picture

Title:How to run javascript: confirm() when Remove button is pressed ?» confirm() dialog when Remove button is pressed ?
drudrew’s picture

Priority:Major» Normal
iantresman’s picture

Yes please, I've lost count of the number of times I've pressed the Remove button, thinking it is a Save button. When I have an image, Description field, Title Field, and extended Caption field, it is a lot of text (and image) to lose in a single click.

quicksketch’s picture

Hi guys, I probably won't be adding this directly to FileField, since this module is no longer receiving features. It should be possible to implement via an add-on module.

As @drudrew noted in the original posting, you can bind an additional handler to the mousedown() event. Then you can use to prevent the triggering of further handlers.

myhemant’s picture

Issue summary:View changes


Please try with this, Its working fine for me.
Create a copy of misc/ajax.js file and put it any custom module and by drupal_add_js() function.
Now modify the
Drupal.ajax = function (base, element, element_settings) { .... // function in beforeSend:

beforeSend: function (xmlhttprequest, options) {
if( ajax.url =='/?q=field_collection/ajax'){ // condition for when click on the Remove button for collection filed module.
if (confirm('Are you sure you want to remove this?')) {
ajax.ajaxing = true;
return ajax.beforeSend(xmlhttprequest, options);
} else{
ajax.ajaxing = true;
return ajax.beforeSend(`xmlhttprequest`, options);

pwolanin’s picture

Category:Support request» Feature request
Status:Active» Closed (won't fix)