I am rendering ajax link as follows:
l(t('Click here'), 'mypath', array('attributes' => array('id' => 'my-id', 'class' => array('use-ajax'))));
How to display confirmation dialog before ajax request is called?
I do it as follows in javascript, like I have found on this thread:
Drupal.behaviors.module = {
attach: function() {
Drupal.ajax['my-id'].beforeSerialize = function () {
if(confirm('Are you sure?'))
return true;
else
return false;
}
}
}
When I click on link, ajax request is not called but the dialog appears. It is ok. The problem is, that after I click "Cancel" in confirmation dialog, Ajax request is then called after closing the confirmation dialog.
Can anybody help, how to get the confirmation dialog work?
options.beforeSerialize
oroptions.beforeSubmit
in place ofbeforeSerialize
? Documentation is pretty bad and I'm not sure which of these 3 is the right way, but it should take you less than 5 minutes to test both. – Mołot Sep 27 '13 at 8:30