Attach an #ajax callback to a field when the form is reloading from previous ajax request Is it possible to attach an #ajax callback to a field when the form is being regenerated from a previous ajax event (like a submit button)? 



What I tried

Adding the #ajax callback to the field when the form is reloading does not seems to trigger anything:

// Adding the ajax event to the field.
$form['my_field']['#ajax'] = array(
  'wrapper' =&gt; 'module_form',
  'callback' =&gt; 'module_form_ajax_callback',
);


The Drupal.settings array is not updated after the end of the ajax process. Seems like I'm trying to do something the Form API isn't able to do out of the box... Here's the result of the first ajax request:

You can see there's still only the submit button in the form attached to an ajax event.

Update

I spotted the issue, it was somewhere else. My form is a multi-steps form, when a step is submitted, I rebuild the form with the previous steps and add the next one. 

For the previous steps, I render them based on data available from $form_state['complete form'], the render array here is actually storing a lot more data than the one I had set in the first place, which was causing conflicts.
#attached Will not be processed properly on elements that was loaded with AJAX. Maybe it could, but it never worked for me. on the other hand, using #ajax worked for me without a fault. what I would try (obviously a guess because you didn't provide full SSCCE) would be:

$field['#ajax'] =&gt; array(
  'wrapper' =&gt; 'module_form',
  'callback' =&gt; 'module_form_ajax_callback',
  'event' =&gt; 'change',
);


If this element is created with an AJAX call from another element, it's AJAX will work.