AnsweredAssumed Answered

How can I create a dependent dropdown?

Question asked by Joana Lopes da Fonseca on Mar 27, 2014
Latest reply on May 13, 2014 by Francesca Shiekh

I trying to create a Dropdown that is dependent of another dropdown, this is, the values that appear in the second dropdown depend of the selected value in the first dropdown. I'm using Sugar CE 6.5.16 and tryed two different approaches. One of them was updating the vardef file of the field of the second dropdown with the code: 

  $dictionary['Account']['fields']['drop2_c'] = array( 
  'name' => 'drop2_c', 
  'type' => 'enum', 
  'options' => 'teste2_list', 
  'visibility_grid'=> array( 
  'trigger' => 'drop1_c', 
  'values' => array( 
  'AAA' => array('AAA_1', 'AAA_2'), 
  'BBB' => array('BBB_1', 'BBB_2'), 
  'CCC' => array('CCC_1','CCC_2')))); 

and in the other approach i used a javascript file: Account.js with the code:

var arr; function Check() { 
if(document.EditView.drop2_c || document.EditView.drop1_c) { 
var drop2_c = document.EditView.drop2_c.options; 
arr = new Array; 
for(i=0; i<drop2_c.length; i++) { 
arr.push(drop2_c[i].value, drop2_c[i].text); 


function initData(){ 
var current_p= document.EditView.drop1_c; 
var code_p = current_p.value; 
var current_v= document.EditView.drop2_c; 
var code_v = current_v.value; 
var code_v_idx = 0; 
var select_ticket = document.EditView.drop2_c.options; 
var l = 0; 
for(k=0; k<arr.length; k+=2) { 
  if(arr[k].substr(0,3) == code_p || arr[k] == '') { 
  select_ticket[select_ticket.length-1].value = arr[k]; 
  select_ticket[select_ticket.length-1].text = arr[k+1]; 
  if(code_v == arr[k]){ 
   code_v_idx = l; 

if(code_p == ''){ 
  select_ticket[select_ticket.length-1].value = ''; 
  select_ticket[select_ticket.length-1].text = 'Select from DD1'; 

document.EditView.drop2_c.selectedIndex = code_v_idx;; 

if (window.addEventListener) 
window.addEventListener("load", Check, false) 
else if (window.attachEvent)
window.attachEvent("onload", Check) 
else if (document.getElementById)

indicating in the editviewdefs.php file the Account.js file.

But i didn't manage to put any of the two tests of dropdown dependent working. 

Does anyone could help me with the dependent dropdowns method to put them working?

Best regards,

Joana Lopes da Fonseca