I have a basic FAPI button input that is #ajax enabled and that's working fine, but I want to add a JS "Are you sure?" confirmation popup when clicking the button before the code actually runs, and I'm not sure how to do that because FAPI's JS seems to be eating the click before I can get to it no matter what I do.
I've tried adding an inline onclick handler, like so:
$form['search_filters']['channels']['channel_delete_' . $channel->nid] = array(
'#type' => 'button',
'#name' => 'channel_delete_' . $channel->nid,
'#value' => 'Delete',
'#attributes' => array(
'class' => array('confirm'),
'onclick' => "return confirm('Are you sure you want to delete that?')"
),
'#button_type' => 'no-submit',
'#ajax' => array(
'callback' => 'delete_channel_callback',
'wrapper' => 'channel_container_' . $channel->nid
),
);
...which doesn't help, and I've also tried adding:
$('.confirm').click(function(e) {
e.preventDefault();
alert('Is this recognized')? // never runs
});
in my module's JS which is also ignored.
Any other ideas? Is there a way to add a submit handler to the top of the stack which Drupal #ajax will recognize?