1

我正在使用表单 API 在模块中构建表单。我有几个相关的下拉菜单一直运行良好。代码如下:

$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 控制台中也出现以下错误:

“未捕获的 TypeError:对象函数 (a,b){return new p.fn.init(a,b,c)} 没有方法 'handleError'”

我在这里做错了什么?

4

0 回答 0