我正在使用Form API在模块中构建一个Form。我有几个依赖的下拉菜单一直工作得很好。代码如下:
$types = db_query('SELECT * FROM {touchpoints_metric_types}') -> fetchAllKeyed(0, 1);
$types = array('0' => '- Select -') + $types;
$selectedType = isset($form_state['values']['metrictype']) ? $form_state['values']['metrictype'] : 0;
$methods = _get_methods($selectedType);
$selectedMethod = isset($form_state['values']['measurementmethod']) ? $form_state['values']['measurementmethod'] : 0;
$form['metrictype'] = array(
'#type' => 'select',
'#title' => t('Metric Type'),
'#options' => $types,
'#default_value' => $selectedType,
'#ajax' => array(
'event' => 'change',
'wrapper' => 'method-wrapper',
'callback' => 'touchpoints_method_callback'
)
);
$form['measurementmethod'] = array(
'#type' => 'select',
'#title' => t('Measurement Method'),
'#prefix' => '<div id="method-wrapper">',
'#suffix' => '</div>',
'#options' => $methods,
'#default_value' => $selectedMethod,
);
以下是_get_methods和touchpoints_method_callback函数:
function _get_methods($selected) {
if ($selected) {
$methods = db_query("SELECT * FROM {touchpoints_m_methods} WHERE mt_id=$selected") -> fetchAllKeyed(0, 2);
} else {
$methods = array();
}
$methods = array('0' => "- Select -") + $methods;
return $methods;
}
function touchpoints_method_callback($form, &$form_state) {
return $form['measurementmethod'];
}
这一切都正常,直到我向表单添加了一个文件字段。这是我用于此的代码:
$form['metricfile'] = array(
'#type' => 'file',
'#title' => 'Attach a File',
);
现在,如果我更改了第一个下拉列表,则会添加该文件,并且旁边会显示“请稍候”消息,而不会加载第二个下拉列表的内容。我的JavaScript控制台中也出现以下错误:
“Uncaught TypeError:Object function(a,b){return new p.fn.init(a,b,c)}没有方法'handleError'”
我在这里做错了什么?