Problem/Motivation
I have a delete confirmation form that is "AJAX-ified". But the AJAX functionalities stop working when the form is displayed via jQuery dialog.
Below is the relevant code that "AJAX-ifies" the confirmation form.
// Add an AJAX callback.
$form['actions']['submit']['#ajax'] = array(
'callback' => 'lq_comment_lq_comment_comment_delete_form_submit_ajax',
'wrapper' => $form['#id'],
);
When viewed normally, the AJAX callback is executed and the form is submitted via AJAX. But when viewed from the jQuery dialog, the form is submitted and the AJAX callback is not executed.
I tried adding ajax.js manually to ensure that the JS file is included via:
$form['ajax_file'] = array(
'#markup' => '<script src="<path to>/misc/ajax.js"></script>',
);
When viewed normally, I can see the line added inside the form but when viewed via jQuery dialog, it seems that the line is stripped.
Is there a way to maintain AJAX functionalities of forms displayed via jQuery dialog?
Thanks!
Comments
Comment #1
drclaw commentedHere's what's happening:
Drupal.settings, but only on the page that it's originally rendered.This is a bit of a tricky one to work around actually. I have two recommendations, but they both require some custom coding. The easiest solution would be to actually add your form to the page (in a block, for example). Then, hide it using css. Then just add your own javascript to show/hide the form in a dialog:
The second option would be to use ctools. Ctools has some cool stuff that helps power AJAX loading of forms as well as modal dialogs. Check out Modal Forms for an example of how it can work.
Hope this helps!
drclaw
Comment #2
angheloko commentedAh, gotcha! Will try them out.
And, I guess this is actually outside of the modules main purpose anyway and the module does what it does best.
Thanks for the looking into this and for the suggestions!