Hey,
I try to get an ajax-request performed by a textfield when creating a node.
I defined a field (node_timeline_archive_url) which is instanced for that node type and therefore the form element is already present when hook_form_alter is invoked.
The following code attaches the div (so I know the code actually is performed on the right element) but my ajax-callback is never run.
function timeline_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'node_timeline_archive_node_form':
$form['node_timeline_archive_url']['#ajax'] = array(
'callback' => 'ajax_check_url_callback',
'wrapper' => 'url-check-div',
'method' => 'replace',
'effect' => 'fade',
);
$form['node_timeline_archive_url']['#suffix'] = '<div id="url-check-div"></div>';
break;
}
}
function ajax_check_url_callback ($form, $form_state) {
return 'Well done - That was Ajax.';
}
However, if I define a new form element with the same ajax properties, the request is performed:
<?php
$form['test'] = array(
'#type' => 'textfield',
'#title' => t('What URL do you want to check?'),
'#ajax' => array(
'callback' => 'ajax_check_url_callback',
'wrapper' => 'url-check-div',
'method' => 'replace',
'effect' => 'fade',