0

I'm using ctools modal for my form and now I need to create dependent selects on form. On first page load all works fine, but when i chose anything in select #ajax callback called and chandes the value of dependent select as needed. But than my ctools modal window is not called on click with error NS_ERROR_XPC_BAD_CONVERT_JS. Here is my code part:

function metrics_company_ajax_callback($form, $form_state){
    $result = db_query('select SMTH FROM SMTH where 
              id='.$form_state['input']['operator']);
    $company = array(); 
    foreach ($result as $comp) {
    $company[$comp->nid] = check_plain($comp->title);
    }
    $form['all']['company'] = array(
    '#type' => 'select',
    '#title' => t('Company'),
    '#options' => $company,
    '#prefix' => '<div id="company">',
    '#suffix' => '</div>',
    );
    $html = drupal_render($form['all']['company']);
    $commands = array();
    $commands[] = ajax_command_html("#company",$html);
    return array('#type' => 'ajax', '#commands' => $commands); 
    }

My form looks like this:

 $form['all']['operator'] = array(
         '#type' => 'select',
               '#title' => t('Operator'),
               '#options' => $opers,
         '#ajax' => array(
           'event' => 'change',
           'callback' => 'metrics_company_ajax_callback',
           'wrapper' => 'company',
         ),

    );
    $form['all']['company'] = array(
         '#type' => 'select',
               '#title' => t('Company'),
               '#options' => $company,
         '#prefix' => '<div id="company">',
         '#suffix' => '</div>',
    );
    $form['all']['state'] = array(
         '#type' => 'select',
               '#title' => t('State'),
               '#options' => $state,
    );

On clicking ctools modal link it returns following:

[{"command":"settings","settings":{"basePath":"\/","pathPrefix":"","ajaxPageState":{"theme":"corolla","theme_token":"mKh_azZMJjL-oFXON65Ul6xXgZwiBzPf19e6mh7xNEk"},"CToolsModal":{"loadingText":"Loading...","closeText":"Close Window","closeImage":"\u003Cimg src=\u0022http:\/\/localhost:8080\/sites\/all\/modules\/ctools\/images

So it goes to another page with ajax response, not opening modal window. Exact JS error:

NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild]

It happens here in jquery.js:

d.appendChild(f[h])}return f},cleanData:function(a){for(var b,d,e=c.cache,f=c.event.special,h=c.support.deleteExpando,l=0,k;(k=a[l])!=null;l++)if(!(k.nodeName&&c.noData[k.nodeName.toLowerCase()]))if(d=k[c.expando]){if((b=e[d])&&b.events)for(var o in b.events)f[o]?c.event.remove(k,o):c.removeEvent(k,o,b.handle);if(h)delete k[c.expando];else k.removeAttribute&&k.removeAttribute(c.expando);delete e[d]}}});var Ea=/alpha\([^)]*\)/i,gb=/opacity=([^)]*)/,hb=/-([a-z])/ig,ib=/([A-Z])/g,Fa=/^-?\d+(?:px)?$/i,

Help is highly appreciated. Thanks

  • You really, and I mean really, must not pass data directly from the form state into a query. If this code happened to hint about which site you where actively working on, you would be publishing to the entire world that your site had a major security issue, and show how to abuse it. On the topic of your actual question, this looks like it's related to Firefox's JavaScript engine, and the question isn't really Drupal related. – Letharion Aug 31 '12 at 9:22
  • Thanks a lot. Ye, hurrying up is never good in programming. – swindler Aug 31 '12 at 11:40
  • According to my error-i'm going to check this under IE. Thanks. – swindler Aug 31 '12 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.