Results 1 to 2 of 2

Thread: 3 dependent level dropdown

  1. #1
    jaybreizh29 Guest

    Default 3 dependent level dropdown

    Hello
    before beginning... i'm french... so sorry for my bad english

    So, i would like to make a system of dependent dropdown ( not only 2 but 3), i have no problem with 2 but when i try with 3 i have problem.

    my inspiration to implement this fonctionality is this tuto : HowTo build related dropdowns in Sugar 5.0.0b

    it works with 2 dependent dropdown but when i want to adapt the code for 3... it doesn't work.

    can you help me?

    i try to make this on module "documents" so juste after you can find the code i tried.

    code of modules/Documents/documents.js

    Code:
    var arr; 
    var arr1;
    
    function Check() { 
    if(document.EditView.niveau_1_c || document.EditView.niveau_2_c || document.EditView.niveau_3_c) { 
        var niveau_2_c = document.EditView.niveau_2_c.options; 
        var niveau_3_c = document.EditView.niveau_3_c.options; 
        
        arr = new Array; 
        arr1= new Array;
        for(i=0; i<niveau_2_c.length; i++) { 
    arr.push(niveau_2_c[i].value, niveau_2_c[i].text); 
    } 
        for(i=0; i<niveau_3_c.length; i++) { 
    arr1.push(niveau_3_c[i].value, niveau_3_c[i].text); 
    } 
    
    
    } 
    initData();
    
    } 
     
    function initData(){ 
        var current_p = document.EditView.niveau_1_c; 
        var code_p = current_p.value; 
     
        var current_v = document.EditView.niveau_2_c; 
        var code_v = current_v.value; 
        var code_v_idx = 0; 
     
        var select_ticket = document.EditView.niveau_2_c.options; 
        select_ticket.length=0; 
        var l = 0; 
        for(k=0; k<arr.length; k+=2) { 
         if(arr[k].substr(0,3) == code_p || arr[k] == '') { 
         select_ticket.length++; 
         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; 
         } 
         l++; 
         } 
        } 
        if(code_p == ''){ 
            select_ticket[select_ticket.length-1].value = ''; 
         select_ticket[select_ticket.length-1].text = 'Choisir Niveau 1'; 
        } 
        document.EditView.niveau_2_c.selectedIndex = code_v_idx;;
    initData2();
    } 
    
    function initData2(){ 
        var current_2 = document.EditView.niveau_2_c; 
        var code_2 = current_2.value; 
     
        var current_3 = document.EditView.niveau_3_c; 
        var code_3 = current_3.value; 
        var code_3_idx = 0; 
     
        var select_ticket = document.EditView.niveau_3_c.options; 
        select_ticket.length=0; 
        var l = 0; 
        for(k=0; k<arr1.length; k+=2) { 
         if(arr1[k].substr(0,5) == code_2 || arr1[k] == '') { 
         select_ticket.length++;
         select_ticket[select_ticket.length-1].value = arr1[k]; 
         select_ticket[select_ticket.length-1].text = arr1[k+1]; 
         if(code_3 == arr1[k]){ 
             code_3_idx = l; 
         } 
         l++; 
         } 
        } 
        if(code_2 == ''){ 
            select_ticket[select_ticket.length-1].value = ''; 
         select_ticket[select_ticket.length-1].text = 'Choisir Niveau 2'; 
        } 
        document.EditView.niveau_3_c.selectedIndex = code_3_idx;;
    }
    
    
    if (window.addEventListener) 
    window.addEventListener("load", Check, false) 
    else if (window.attachEvent)
    window.attachEvent("onload", Check) 
    else if (document.getElementById)
    window.onload=Check
    and the code of custom/modules/Documents/metadata/editviewdefs.php

    Code:
    array (
              0 => 
              array (
                'name' => 'niveau_1_c',
                'studio' => 'visible',
                'label' => 'LBL_NIVEAU_1',
                'displayParams' => 
                array (
                  'javascript' => 'onchange="initData();"',
                ),
              ),
            ),
            1 => 
            array (
              0 => 
              array (
                'name' => 'niveau_2_c',
                'studio' => 'visible',
                'label' => 'LBL_NIVEAU_2',
                            'displayParams' => 
                array (
                  'javascript' => 'onchange="initData2();"',
                ),
              ),
            ),
            2 => 
            array (
              0 => 
              array (
                'name' => 'niveau_3_c',
                'studio' => 'visible',
                'label' => 'LBL_NIVEAU_3',
              ),
            ),

  2. #2
    jaybreizh29 Guest

    Default Re: 3 dependent level dropdown

    heu... I feel... alone !
    anyone with same problem?

    no body can help me?

    it will be very cool if someone can help me because idon't know how to resolve me problem

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. 3 dependent level dropdown
    By jaybreizh29 in forum Developer Help
    Replies: 0
    Last Post: 2013-09-10, 04:19 PM
  2. Dependent dropdown
    By saj123 in forum Help
    Replies: 1
    Last Post: 2013-03-18, 07:27 AM
  3. Replies: 2
    Last Post: 2013-02-04, 10:54 PM
  4. Dependent Dropdown - Help!
    By m3suriya in forum Developer Help
    Replies: 0
    Last Post: 2010-11-27, 06:09 AM
  5. Replies: 3
    Last Post: 2009-11-18, 11:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •