Drupal 7: File field causes error with Dependable Dropdowns

Posted by LoneWolfPR on Stack Overflow See other posts from Stack Overflow or by LoneWolfPR
Published on 2012-10-25T21:24:56Z Indexed on 2012/10/25 23:01 UTC
Read the original article Hit count: 314

I'm building a Form in a module using the Form API. I've had a couple of dependent dropdowns that have been working just fine. The code is as follows:

$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,
);

Here are the _get_methods and touchpoints_method_callback functions:

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'];
}

This all worked fine until I added a file field to the form. Here is the code I used for that:

$form['metricfile'] = array(
    '#type' => 'file',
    '#title' => 'Attach a File',
);

Now that the file is added if I change the first dropdown it hangs with the 'Please wait' message next to it without ever loading the contents of the second dropdown. I also get the following error in my JavaScript console:

"Uncaught TypeError: Object function (a,b){return new p.fn.init(a,b,c)} has no method 'handleError'"

What am I doing wrong here?

© Stack Overflow or respective owner

Related posts about drupal-7

Related posts about drupal-modules

  • Commercial Drupal Modules & Themes

    as seen on Just Skins - Search for 'Just Skins'
    A discussion at Drupal.org forums prompted me to give my input about commercial ecosystem around Open Source Content Management Systems. WordPress and Joomla have been growing rapidly since past few years. But, growth rate of Drupal seems to be almost flat. Despite being the most powerful CMS around… >>> More

  • Drupal Modules for SEO & Content

    as seen on Just Skins - Search for 'Just Skins'
    When we talk about Drupal SEO, there are two things to consider one is about the relevant SEO practices and about appropriate Drupal Modules available. Optimizing your website for search engines is one of the most important aspect of launching & promoting your website especially if ranking matters… >>> More

  • Drupal modules for ticketing system

    as seen on Server Fault - Search for 'Server Fault'
    Hi All, We are looking at implementing a ticketing system at our work place. We intially tried OS Ticket which was fine. But management are hoping to integrate it into out intranet. (which will be done in Drupal) The Ticketing system will be used for the IT Team. Are there any modules available… >>> More

  • Add drupal modules on ec2 server

    as seen on Server Fault - Search for 'Server Fault'
    how do I add external drupal modules to an ec2 server? Drupal interface wants me to provide ftp password, but amazon ec2 uses private key pair and not username/password (unless I enable that, which I don't want to) how would I install from a site like this http://drupal.org/project/restws if the… >>> More

  • OO and Writing Drupal Modules

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Preface: Yes, I've read: http://drupal.org/node/547518 I am writing 'foo' module for Drupal6, where I am organizing the code in an OO fashion. There's a class called Foo that has a bunch of setters and accessors, and it is working quite well at abstracting some pretty nasty code and SQL. The question… >>> More