How to invoke autodialog module close method in autodialog.js file using ajax_command_invoke

by iamroald   Last Updated August 21, 2016 08:04 AM - source

I have form that loads in modal using autodialog module and I have two buttons inside the form the close and save button. What I am trying to achieve is to just close the modal when the close button is clicked. I can do this using jQuery but what I wanted to do is use ajax_command_invoke to invoke autodialog close to close the modal. so far this what I have done, but I can't make it work maybe I am doing it wrong.

function example_autodialog_close_form_submit($form, &$form_state) {
  switch($form_state['clicked_button']['#value']) {
    case 'Closed':
      $commands[] = ajax_command_invoke('.autodialog-content', 'dialog', array('close'));
    case 'Save':
      // Insert data in database.
  return array('#type' => 'ajax', '#commands' => $commands);

Using jQuery, this one work but what I wanted is use ajax_command_invoke to invoke auto dialog close.

$('#autodialog-close').click(function() {

Some code snippet in autodialog module autodialog.js file.

  Drupal.ajax.prototype.commands.autodialog = function (ajax, response, status) {
    var options = {
      title: response.title,
      width: 500,
      modal: true,
      closeText: Drupal.t('Close'),
      close: function () {
    $.extend(options, response.options);

    // Close previous dialog
    if (options.closeprev) {

    // Create dialog content
    var $dialogContent = $('' + response.content + '').appendTo('body');

    // Open dialog. Not $dialog.dialog() because it causes problems with inline scripts for jQuery 1.4.
    $('#' + response.dialog_id).dialog(options);

    // Remove focus from first tabbable element

    // Close dialog when clicked outside
    $('.ui-widget-overlay:last').click(function (event) {
      if ($('ui-widget-overlay')) {


Related Questions

Decoding cyrillic %get[] parameter in Ajax form

Updated June 11, 2015 08:03 AM

Access Denied when Menu CallBack Function is Called

Updated April 20, 2015 06:03 AM