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' => 'module_form',
'callback' => '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.
$form
variable in your first block of code?module_form_ajax_callback
return $form;
, but I think I spotted the issue, it was somewhere else. My form is a multi-steps form, when the first step is submitted, I rebuild the form with with the first step and the new one. For the 1st step, I render it based on data available into $form_state['complete form'], the render array is actually different from the one I set in the first place, which creates problems. I need to make sure of that, if that's the issue, I'll write an answer and edit the question to make things more clear.