Results 1 to 10 of 10
Like Tree2Likes
  • 1 Post By kir
  • 1 Post By kir

Thread: One dropdown effect another dropdown values

  1. #1
    rodnikosh Guest

    Default One dropdown effect another dropdown values

    i want one dropdown selection to effect another dropdown values,
    for example: one dropdown is the cellular brand (or company) and when choosing the brand, i get in the other dropdown the models of the brand ( i5, i4 ....).

    i'm going to do that by filling the second dropdown with the result of a query execution on the database using the value of the first dropdown as a parameter.
    the two columns (brands and models) are ready in the database.

    can you give me some pointers of how to do that ?

    should i use javascript ? for example: customcode - "onblur" function that will execute a JS function that will return the values ?
    or there are simplier ways in PHP or some kind of SugarCRM mechanism that will make it easier?
    i really don't want to write it all in javascript....
    i already know how to query the database in Sugar ($GLOBALS['db']->fetchByAssoc ... )

    Thank you.

  2. #2
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: One dropdown effect another dropdown values

    Quote Originally Posted by rodnikosh View Post
    i want one dropdown selection to effect another dropdown values,
    for example: one dropdown is the cellular brand (or company) and when choosing the brand, i get in the other dropdown the models of the brand ( i5, i4 ....).

    i'm going to do that by filling the second dropdown with the result of a query execution on the database using the value of the first dropdown as a parameter.
    the two columns (brands and models) are ready in the database.

    can you give me some pointers of how to do that ?

    should i use javascript ? for example: customcode - "onblur" function that will execute a JS function that will return the values ?
    or there are simplier ways in PHP or some kind of SugarCRM mechanism that will make it easier?
    i really don't want to write it all in javascript....
    i already know how to query the database in Sugar ($GLOBALS['db']->fetchByAssoc ... )

    Thank you.
    read this post SugarCRM Developer Blog Blog Archive Learning Sugar Logic: Dynamic Dropdown Subindustry field

    hope it might help you

  3. #3
    ashdwi1's Avatar
    ashdwi1 is offline Sugar Community Member
    Join Date
    May 2008
    Location
    Noida
    Posts
    427

    Default Re: One dropdown effect another dropdown values

    which version of sugar you are using?

  4. #4
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: One dropdown effect another dropdown values

    rodnikosh likes this.

  5. #5
    rodnikosh Guest

    Default Re: One dropdown effect another dropdown values

    Thanks guys , right now i'm developing on the community Edition version 6.5.9 (but in my business i have CE 6.4.3).

  6. #6
    rodnikosh Guest

    Default Re: One dropdown effect another dropdown values

    Thanks Kir, i already know how to fill a dropdown from a function inside the file : custom/Extension/application/Ext/Utils/Utils.php but what is the trigger in sugarCRM that when i select one of the Dropdowns options , the function gets called ? maybe i can activate a function when a selection is made....

  7. #7
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: One dropdown effect another dropdown values

    Quote Originally Posted by rodnikosh View Post
    Thanks Kir, i already know how to fill a dropdown from a function inside the file : custom/Extension/application/Ext/Utils/Utils.php but what is the trigger in sugarCRM that when i select one of the Dropdowns options , the function gets called ? maybe i can activate a function when a selection is made....
    I can advice you to look through Opportunities module
    There you can find implementation of some kind of dependecny dropdown for probability
    metadata/editviewdefs.php & views/view.edit.php work together via {$PROBABILITY_SCRIPT}

    PHP Code:
    $viewdefs['Opportunities']['EditView'] = array(
        
    'templateMeta' => array('maxColumns' => '2'
                                
    'widths' => array(
                                                array(
    'label' => '10''field' => '30'), 
                                                array(
    'label' => '10''field' => '30')
                                                ),
        
    'javascript' => '{$PROBABILITY_SCRIPT}',
    ),
    //.... 
    PHP Code:
    class OpportunitiesViewEdit extends ViewEdit {

         function 
    OpportunitiesViewEdit(){
             
    parent::ViewEdit();
             
    $this->useForSubpanel true;
         }
         
         function 
    display() {
            global 
    $app_list_strings;
            
    $json getJSONobj();
            
    $prob_array $json->encode($app_list_strings['sales_probability_dom']);
            
    $prePopProb '';
             if(empty(
    $this->bean->id) && empty($_REQUEST['probability'])) {
               
    $prePopProb 'document.getElementsByName(\'sales_stage\')[0].onchange();';
            }
            
    $probability_script=<<<EOQ
        <script>
        prob_array = $prob_array;
        document.getElementsByName('sales_stage')[0].onchange = function() {
                if(typeof(document.getElementsByName('sales_stage')[0].value) != "undefined" && prob_array[document.getElementsByName('sales_stage')[0].value]
                && typeof(document.getElementsByName('probability')[0]) != "undefined"
                ) {
                    document.getElementsByName('probability')[0].value = prob_array[document.getElementsByName('sales_stage')[0].value];
                    SUGAR.util.callOnChangeListers(document.getElementsByName('probability')[0]);

                } 
            };
        $prePopProb
        </script>
    EOQ;
            
            
    $this->ss->assign('PROBABILITY_SCRIPT'$probability_script);    
             
    parent::display();
         }
    }
    ?> 
    looks closer?
    rodnikosh likes this.

  8. #8
    rodnikosh Guest

    Default Re: One dropdown effect another dropdown values

    Thanks kir , for your time and effort
    i think the above javascript is a bit too much for my knowledge in javascript.

    what i need is to call a function , almost like the one i put in custom/Extension/application/Ext/Utils/Utils.php for the first dropdown:


    function FillFirstDropdown()
    {

    $myQuery = "select primary_address_city from contacts";
    $myResult=$GLOBALS['db']->query($myQuery);

    while ($myRow = $GLOBALS['db']->fetchByAssoc($myResult))
    {
    $myArray [$myRow['primary_address_city']] = $myRow['primary_address_city'];
    }

    return $myArray;

    }

    and when choosing a city in the first dropdown ,
    to call a function that gets the chosen city as a parameter and fills the seconds dropdown with another query result with street names in that city.

    it's my third hour for finding a solution,
    i found this link on dependant dropdowns:
    SugarCRM Developer Blog Blog Archive Learning Sugar Logic: Dynamic Dropdown Subindustry field
    but this solution is for a limited , few , values in each category. my dropdown will be filled with 50 street atleast for each city chosen in the first dropdown.

    i also tried to read about Sugar_Logic in the developer guide about hooks, trigger, triggerfields...
    Sugar DeveloperZone - SugarCRM Developer Documentation, Sugar Documentation
    i have to say that although my 10 years experience in programming, i couldn't understand a word there and the examples are for pros only.

    still searching....

  9. #9
    rodnikosh Guest

    Default Re: One dropdown effect another dropdown values

    Thanks Kir, i guess you were right, after reading lots of posts and especially this link:
    How to create Dependent Dropdown for state and city?
    i can see that there is no escape from doing this in Javascript...

    Implementing a call to the database in js in order to extract a column from a table (Streets) will certainly be a challenge

  10. #10
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: One dropdown effect another dropdown values

    Quote Originally Posted by rodnikosh View Post
    Thanks Kir, i guess you were right, after reading lots of posts and especially this link:
    How to create Dependent Dropdown for state and city?
    i can see that there is no escape from doing this in Javascript...

    Implementing a call to the database in js in order to extract a column from a table (Streets) will certainly be a challenge
    May be this one will help you too Dynamic Dropdown Two Selects

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 2012-11-02, 08:38 PM
  2. How to save dropdown values into DB
    By meronia in forum Developer Tutorials
    Replies: 3
    Last Post: 2009-08-19, 11:28 AM
  3. Get dropdown values
    By spyro187 in forum Developer Help
    Replies: 1
    Last Post: 2008-06-14, 11:28 AM
  4. dropdown values for a domain
    By singingbowl in forum Developer Help
    Replies: 1
    Last Post: 2007-11-21, 08:42 AM
  5. bug:dropdown without values cannot be edited
    By Lars.Englund in forum Help
    Replies: 0
    Last Post: 2006-10-26, 09:47 AM

Tags for this Thread

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
  •