2

I'm stuck because whatever I do my wrapper is never filled with my callback, any idea ?


  $form['show_liste_produits'] = array(
   '#type' => 'button',
   //'#attributes' => array('onclick' => 'return (false);'),
   '#value' => t('Lister les produits'),
   '#name'  => 'awesome-button',
   '#ajax' => array(
      'callback' => 'stockerAll',
      'wrapper' => 'listeProduits',
      'method'   => 'replace',
      'effect'   => 'fade',
    ),
  );

  $form['listeProduits'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'id' => array('listeProduits'),
    ),
  );

function stockerAll($form, $form_state){
 return 'test';
}

Thank you in advance !

EDIT: In fact in the network tab I get this, maybe the selector isn't working ? Moreover, my empty container isn't displayed after page load actually, maybe is it the source of the problem ?

0

1 Answer 1

0

Edit your code into the code below:

 $form['show_liste_produits'] = array(
     '#type' => 'submit',   
     '#value' => t('Lister les produits'),   
     '#ajax' => array(
         'callback' => 'stockerAll',
         'wrapper' => 'listeProduits',      
     ),
);

$form['listeProduits'] = array(
    '#type' => 'container',
    '#attributes' => array('id'=> 'listeProduits'),         
);

If it doesnt work,make sure first if stockerAll is called. Insert watchdog('test','test'); in the stockerAll function . After doing so, run the program, check your drupal database, particularly the watchdog table and check whether 'test' is in the latest log.

function stockerAll($form, $form_state){
    watchdog('test','test');
    return 'test';
}

If stockerAll is called, clear cache of the browser to make sure the updated code is the one executing. Else, there's something wrong with the way you invoke your function.

5
  • Your code didn't solve the problem (but it was a good idea). In fact in the network tab I get this, maybe the selector isn't working ? Moreover, my empty container isn't displayed after page load actually, maybe is it the source of the problem ?
    – Germain
    Jun 3, 2015 at 8:24
  • @Germain67 --> Did you found the 'test' message in the watchdog table in the drupal database? Jun 3, 2015 at 8:30
  • --> Yes it is in the watchdog table (and the function returned something as you can see on the picture), so the callback is technically working.
    – Germain
    Jun 3, 2015 at 8:34
  • I tried my code above and it's working with me. You must display your code completely for reader's better comprehension. Jun 3, 2015 at 8:43
  • I finally found what was wrong, my ajax callback was in conflict with another event in my javascript file, thank you for you help :)
    – Germain
    Jun 3, 2015 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.