I have an entity reference field, and I'd like to do some ajax so that when a value is selected for that field, some text is displayed in a div below the field. Since it's on a node edit form, I'm using a form alter hook:
/** * Implementation of hook_form_FORM_ID_alter() */ function mymodule_form_blog_node_form_alter(&$form, &$form_state, $form_id) { $form['field_video_reference']['#ajax'] = array( 'callback' => 'mymodule_video_ajax_callback', 'wrapper' => 'my-path-div', ); $form['my_path'] = array( '#markup' => t('My path'), '#prefix' => '<div id="my-path-div">', '#suffix' => '</div>', '#weight' => 6, ); if (!empty($form_state['node']->field_video_reference)) { $form['my_path']['#markup'] = 'Token path: http://www.mysite.org/node/' . $form_state['node']->field_video_reference['und'][0]['target_id']; } } function mymodule_video_ajax_callback($form, $form_state) { return $form['my_path']; } The code works fine when a the form is displayed and the field already has a value. However, the most likely use will be when the node is first being created, so I want this to trigger when a value is first added. The problem is, my callback is not being triggered at all. I'm following the first example in the "Javascript in Drupal" chapter in "Drupal 7 module Development," so from what I see, I it should be called when the field value is changed. Does this not work for fields that are already using ajax to get a value in the first place (i.e. an autocomplete field like this one), or is there something else I'm missing?
Thanks.
UPDATE: In case it is an issue with doing this on an autocomplete field, I added another test field that is a select list and attached the ajax to it as above, but the form is still not rebuilt when I select a value.