I'm trying to register an ajax listener to a checkbox on one of my standard node forms. I want to display certain regions of the form only in case, the field is checked. I can get the drupal ajax ecosystem to work, when I use it in a custom form, but I'm unable to make it work on my node forms.
First I hook into form_alter to check if I'm with the node type I want to add the listener for:
function interceptor_form_alter(&$form, &$form_state, $form_id) {
if($form_id === 'film_node_form') {
interceptor_dvd_listener($form, $form_state);
}
}
Then I try to attach the ajax stuff to my checkbox, which name is field_dvd:
function interceptor_dvd_listener(&$form, &$form_state) {
$form['field_dvd'] = array(
'#title' => t('You want to display DVD informations too?'),
'#type' => 'checkbox',
'#ajax' => array(
'callback' => 'interceptor_dvd_listener_callback',
'wrapper' => 'checkboxes-div',
'effect' => 'slide',
'progress' => array('type' => 'none'),
),
);
return $form;
}
The function interceptor_dvd_listener_callback is never called. I try to print some debug information there, but nothing happens...
function interceptor_dvd_listener_callback($form, $form_state) {
data_service_log_object($form);
}
UPDATE
After passing $form as reference to interceptor_dvd_listener the ajax callback function got called like expected. I edited my code above.