I am somewhat new to Drupal development. Please bear with me on this.
I am trying to create a popup after a user enters a value in a date field on a node/add form. This is on a Drupal 9 site. To do this I am trying to add a callback function to my field.
I have my form_alter hook that I know is working because I have other changes that already work as well I have a logger to tell me that code is running in this block.
This is the code I have added to invoke the callback.
$form['field_birthdate']['widget']['#prefix'] = '<div id="field-birthdate-custom-wrapper">';
$form['field_birthdate']['widget']['#suffix'] = '</div>';
$form['field_birthdate']['widget']['#ajax'] = [
'callback' => '_custom_age_check_pop_up',
'disable-refocus' => FALSE,
'event' => 'change',
'wrapper' => 'field-birthdate-custom-wrapper',
];
I also have my callback function in my module.
function _custom_age_check_pop_up(&$form, FormStateInterface $form_state) {
\Drupal::logger('custom')->error('Age check pop_up');
...
}
The Drupal logger in the _custom_age_check_pop_up function does not fire.
If I do a var_dump of $form['field_birthdate']
before I modify 'field_birthdate'
and then again after I can see that my changes to the field is modifying the field. The AJAX key shows the call back and the other items added in the code above.
There are no error messages in the JS Console in Chrome. I have tried the basic things like clearing the cache.
I am using an example of code that I know worked where it was used before. I am unsure why this is not working for me.
I appreciate any help with this.
Thanks!