Hello, I've a page with a link who open a form via jQuery UI Dialog, this page has a simple form with a plupload element. When I click on submit it send all data via ajax and all works ok, but if I add 'autosubmit' => TRUE to form, it reload the entire page and not call the right ajax callback. How can I perform this operation ?

thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

csedax90’s picture

Version: 7.x-2.x-dev » 7.x-1.4
slashrsm’s picture

Have you tried to also set #submit_element?

joelstein’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Status: Active » Needs review

I had this same issue. I want to not auto-upload (so that users could continue building their list of files) but I do want to auto-submit a button after uploading.

In my use case, I have an ajax button that I want to click after clicking the "Start upload" link in the Plupload widget.

However, it seems that the #autosubmit setting only applies if the #autoupload setting is enabled.

I don't think that should be the case. I see times where you'd want to automatically perform some action after uploading, even if not auto-uploading.

Here's a patch which lets you use #autosubmit with #submit_element. Here's an example of how this could be used:

$submit_id = drupal_html_id('plupload-submit');
$form['files'] = array(
  '#type' => 'plupload',
  '#plupload_settings' => array(
    'runtimes' => 'html5',
    'chunk_size' => '1mb',
  ),
  '#autosubmit' => TRUE,
  '#submit_element' => '#' . $submit_id,
  // plupload_element_value() needs an explicit ID, but not auto-generated with drupal_html_id().
  '#id' => 'plupload-files',
);
$form['upload'] = array(
  '#type' => 'submit',
  '#value' => t('Upload'),
  '#id' => $submit_id,
  '#submit' => array('my_submit_callback'),
  '#limit_validation_errors' => array(
    array('files'),
  ),
  '#ajax' => array(
    'callback' => 'my_ajax_callback',
    'wrapper' => 'some-wrapper-id',
    'event' => 'click',
  ),
  '#attributes' => array('class' => array('js-hide')),
);

It hides the ajax button, but then Plupload's JS will click it automatically after uploading all the files. Works like a charm!

joelstein’s picture

Oops, here's the patch.