I'm trying to clone with jQuery the block which contain a form with an ajax event.

function module_api_change_currency_form($form, &$form_state){    
    $form['currencies'] =  array(
        '#type' => 'select',
        '#options' => array(1 => 'GBP', 2 => 'EUR' , 3 => 'USD'),
        '#default_value' => $_SESSION['currency']['id'],
        '#ajax' => array(
            'callback' => 'ajax_callback_change_currency',
    return $form;   

function ajax_callback_change_currency($form, &$form_state){
 //...other code before
    $commands = array();
    $commands[] = ajax_command_invoke(null, 'changePricesPrincingPage');

    return array('#type' => 'ajax', '#commands' => $commands);   

which give this code:


The original works fine but the clone which I copy with jQuery.clone(true, true) doesn't get the ajax events: It should get inplemented with those arguments: clone([withDataAndEvents] [, deepWithDataAndEvents]) but it doesn't work :(

The 2 forms (select) are exactly the same. Any Idea how I can get the ajax event working on the clone?

  • It doesn't get AJAX events because you do not attach them. Drupal would do it for you if you would use Drupal's AJAX to provide new elements. But that's not a problem anyway - form elements created like that will not be usable in Form API, Drupal will not accept values from them, so why would you bother with events? Use AJAX, Drupal implementation, to create elements on the fly if needed.
    – Mołot
    Commented Sep 7, 2015 at 13:00
  • How can I attached them in that case? What do you mean by creating element on the fly? How can I do that?
    – GwenM
    Commented Sep 7, 2015 at 13:12
  • drupal.org/node/752056
    – Mołot
    Commented Sep 7, 2015 at 13:13


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.