Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a form using Entity forms and attaching an AJAX callback to an existing field in hook_FORM_form_id_alter(). So far I have no luck with any ajax callbacks.
<?php
function hook_FORM_form_id_alter(&$form, &$form_state, $form_id) {
. . .
// An existing field.
$form['existing_field']['#ajax'] = array(
'callback' => 'test_callback',
'wrapper' => 'test-wrapper',
);
// My container.
$form['container'] = array(
'#prefix' => '<div id="test-wrapper">',
'#suffix' => '</div>',
);
. . .
}
test_callback($form, &$form_state) {
dpm($form_state);
}
I left out a bulk of my code but this is the basic idea. Any suggestions?
Comments
Comment #2
jfurnas CreditAttribution: jfurnas commentedYou need to target a specific delta for the fields in order get it to work. In example, your code should look like this: