Drupal 7: AJAX Form Update issue
-
06-07-2021 - |
Domanda
I have the following elements defined in my form hook:
$form['touchpointdivision'] = array(
'#type' => 'select',
'#title' => t('Division'),
'#options' => $divisions,
'#required' => TRUE,
'#ajax' => array(
'event' => 'change',
'wrapper' => 'department-wrapper',
'callback' => 'touchpoints_dept_callback',
'method' => 'replace'
)
);
$form['touchpointdepartment'] = array(
'#type' => 'select',
'#title' => t('Department'),
'#prefix' => '<div id="department-wrapper">',
'#suffix' => '</div>',
'#options' => _get_departments($selected),
'#required' => TRUE
);
Here's the callback:
function touchpoints_dept_callback($form, $form_state){
return $form('touchpointdepartment');
}
When I change an item in the first dropdown I get the following error:
"Fatal error: Function name must be a string in /cmi/sites/all/modules/touchpoints/touchpoints.module on line 203"
What am I missing in this declaration?
Soluzione
Wow, dumb mistake. In the callback the fieldname should be in brackets not parentheses. So:
function touchpoints_dept_callback($form, $form_state){
return $form('touchpointdepartment');
}
should be
function touchpoints_dept_callback($form, $form_state){
return $form['touchpointdepartment'];
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow