Score:0

Checkbox Ajax call back giving me error

ma flag

New to drupal 7, following code should work fine according to my knowledge can someone help me why ajax give me error in console ? and what the solution

Code

function user_activity_tree_structure_showoptional_form($form, &$form_state, $base_nid) {
      $form['enablecond'] = array(
        '#type' => 'checkbox',
        '#title' => "Checkbox  ",
        '#ajax' => array(
        'callback' => 'ajaxcall_func',
        'progress' => 'false',
      ),
    );
    return $form;
}


function ajaxcall_func(&$form, $form_state) 
{
    setcookie("checkbox_1",$form['enablecond']["#value"]);
    return null;
}

Console Error

js_Y5H_CdmZpIvEir8-B6htnqHb6_vJBznC3jPygHLV6dE.js:495 Uncaught TypeError: Cannot read property 'Drupal' of undefined
at Object.attach (js_Y5H_CdmZpIvEir8-B6htnqHb6_vJBznC3jPygHLV6dE.js:495)
at Object.<anonymous> (js_UYCsqqVg9hDgzN1bjf7T6Fy66IJRk810uQF1qy9Lgo4.js:61)
at Function.each (js_H_BqcoIBkzDSvN9rxK_RAvqVRCfKG3dcLloVRen-E84.js:4)
at Object.Drupal.attachBehaviors (js_UYCsqqVg9hDgzN1bjf7T6Fy66IJRk810uQF1qy9Lgo4.js:59)
at Drupal.ajax.success (js_Y5H_CdmZpIvEir8-B6htnqHb6_vJBznC3jPygHLV6dE.js:2127)
at Object.success (js_Y5H_CdmZpIvEir8-B6htnqHb6_vJBznC3jPygHLV6dE.js:1858)
at Object.c.success (js_Y5H_CdmZpIvEir8-B6htnqHb6_vJBznC3jPygHLV6dE.js:111)
at c (js_H_BqcoIBkzDSvN9rxK_RAvqVRCfKG3dcLloVRen-E84.js:4)
at Object.fireWith [as resolveWith] (js_H_BqcoIBkzDSvN9rxK_RAvqVRCfKG3dcLloVRen-E84.js:4)
at k (js_H_BqcoIBkzDSvN9rxK_RAvqVRCfKG3dcLloVRen-E84.js:6)
Kevin avatar
in flag
Ajax callbacks need to return the form or part of the form. https://www.drupal.org/docs/7/api/javascript-api/ajax-forms-in-drupal-7
Score:0
ma flag

There was actually a conflict between Drupal 7 - contributed module -> navbar -> js -> displace.js with fancytree.js.

Just answering this question so that you should make sure that any third party library shouldn't conflict with core and contributed modules js libraries.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.