Page 1 of 9 12345 ... LastLast
Results 1 to 10 of 81

Thread: HowTo build related dropdowns in Sugar 5.0.0b

  1. #1
    DragonflyMaster is offline Sugar Community Member
    Join Date
    Dec 2007
    Location
    Rimini, Italy
    Posts
    1,421

    Default HowTo build related dropdowns in Sugar 5.0.0b

    Some time ago I was asked to explain how I succeeded in creating related dropdowns in sugar 5.x.
    First of all, I'd like to say that other sugar developers managed to build such dropdowns and some of them helped me understand how to do. Thanks guys.

    I started taking ideas from a pdf file found in the wiki pages; that document was about building related dropdowns in Sugar 4.5.1 and was written by Synolia, a french SugarCRM Recognized Developer.
    I suggest to those willing to create related dropdowns to give it a look, the file is: Combos Liees dans SugarCRM V1.2.pdf
    you can find it here with other documents published by Synolia:
    http://www.sugarforge.org/frs/?group_id=11

    Now let's see how to build two related dropdowns (I made it for EditView in Accounts module).
    1. build the first dropdown
    2. when adding new couples value-text in dropdown, use 3-chars values, like:'AAA', 'BBB', 'XXX'.
    3. build the second dropdown
    4. when adding new couples value-text in dropdown, use values having prefix = related value of dropdown one, like 'AAA_1' 'AAA_2' 'BBB_1' 'BBB_2' and so on.
    5. open file editviewdef.php to be used with the module you are placing the dropdowns in (in my case the module was Accounts, so I opened <sugar-root>\modules\Accounts\metadata\editviewdef.php)
    6. add an include to a javascript file (in my case I didn't add anything because Accounts.js was already included:
      Code:
      $viewdefs['Accounts']['EditView'] = array(
      	'templateMeta' => array(
      							'form' => array('buttons'=>array('SAVE', 'CANCEL')),
      							'maxColumns' => '2', 
      							'widths' => array(
      											array('label' => '10', 'field' => '30'),
      											array('label' => '10', 'field' => '30'),
      											),
      						 'includes'=> array(
      											array('file'=>'modules/Accounts/Account.js'),
      										 ),
      						 ),
    7. append the following code in the .js file that you just included (in my case <sugar-root>\modules\Accounts\Account.js) :
      Code:
      var arr; 
      function Check() { 
      if(document.EditView.DropDown2_c || document.EditView.DropDown1_c) { 
      	var DropDown2_c = document.EditView.DropDown2_c.options; 
      	arr = new Array; 
      	for(i=0; i<DropDown2_c.length; i++) { 
      arr.push(DropDown2_c[i].value, DropDown2_c[i].text); 
      } 
      } 
      initData(); 
      } 
       
      function initData(){ 
      	var current_p= document.EditView.DropDown1_c; 
      	var code_p = current_p.value; 
       
      	var current_v= document.EditView.DropDown2_c; 
      	var code_v = current_v.value; 
      	var code_v_idx = 0; 
       
      	var select_ticket = document.EditView.DropDown2_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 = 'Select from DD1'; 
      	} 
      	document.EditView.DropDown2_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)
      window.onload=Check
    8. Open the editviewdefs.php file where your dropdowns are (in my case <sugar-root>\custom\modules\Accounts\metadata\editviewdef s.php and locate your first dropdown:
      Code:
      array (
      			 'name' => 'DropDown1_c',
      			 'label' => 'LBL_DROPDOWN1',
      			),
    9. Add the following code after 'label':
      Code:
      'displayParams' => array (
      				 'javascript' => 'onchange="initData();"'
      				 ),
    10. Point 8 and 9 should result in this:
      Code:
      array (
      			 'name' => 'DropDown1_c',
      			 'label' => 'LBL_DROPDOWN1',
      			 'displayParams' => 
      			 array (
      				'javascript' => 'onchange="initData();"',
      			 ),
      			),
    That's all.
    Big thanks to Synolia for publishing their document.
    Thanks to jstukas for asking me about this.
    What do you think the cookie monster eats ?

  2. #2
    cagagay is offline Junior Member
    Join Date
    Mar 2008
    Posts
    1

    Default Re: HowTo build related dropdowns in Sugar 5.0.0b

    Hi DragonflyMaster

    Thanx a lot for this great job. I need this but never tried yet
    By the way suggest that there is 4 dropdown ( so 4 related dropdown also) in EditView, what will we do?

    I am planning 4 dropdown and each has thier own related dropdown,

    Meanwhile can we open an automatic (related) TEXTFIELD instead of related dropdown?

    Best Regards...

    CK

  3. #3
    julian's Avatar
    julian is offline Sugar Team Member
    Join Date
    Sep 2004
    Posts
    1,639

    Default Re: HowTo build related dropdowns in Sugar 5.0.0b

    DragonflyMaster,

    This looks great! Would you consider adding this walkthrough to the Developer Wiki? I've seen this question come up quite a few times in the Developers forum.

    http://www.sugarcrm.com/wiki/index.p...Developer_Wiki
    Julian Ostrow
    Systems and Applications Engineer
    SugarCRM Inc.

  4. #4
    DragonflyMaster is offline Sugar Community Member
    Join Date
    Dec 2007
    Location
    Rimini, Italy
    Posts
    1,421

    Default Re: HowTo build related dropdowns in Sugar 5.0.0b

    Quote Originally Posted by julian
    DragonflyMaster,

    This looks great! Would you consider adding this walkthrough to the Developer Wiki? I've seen this question come up quite a few times in the Developers forum.

    http://www.sugarcrm.com/wiki/index.p...Developer_Wiki
    Hi Julian,

    I've seen the question in the forum many times too, that's why I decided to open this thread.
    If you think my walkthrough is good enough for the Wiki, I'll gladly consider adding it.
    Just tell me how to proceed, and I'll do it.
    Last edited by DragonflyMaster; 2008-03-28 at 02:06 PM.
    What do you think the cookie monster eats ?

  5. #5
    DragonflyMaster is offline Sugar Community Member
    Join Date
    Dec 2007
    Location
    Rimini, Italy
    Posts
    1,421

    Default Re: HowTo build related dropdowns in Sugar 5.0.0b

    Quote Originally Posted by cagagay
    By the way suggest that there is 4 dropdown ( so 4 related dropdown also) in EditView, what will we do?

    I am planning 4 dropdown and each has thier own related dropdown
    Hi CK,

    so far I needed to build such a thing with 3 dropdowns only, and it worked fine.
    I'm pretty sure it can work with 4 or more related dropdowns too.

    Quote Originally Posted by cagagay
    Meanwhile can we open an automatic (related) TEXTFIELD instead of related dropdown?
    Of course you can, you just need to replace the javascript function with one that shows a textfield.
    You can take inspiration for this from the addEmailAddress() function called from the "Add email address" link inside the Email Address form that appears in account's or contact's editview.
    What do you think the cookie monster eats ?

  6. #6
    DragonflyMaster is offline Sugar Community Member
    Join Date
    Dec 2007
    Location
    Rimini, Italy
    Posts
    1,421

    Default Re: HowTo build related dropdowns in Sugar 5.0.0b

    I transposed this post of mine into the Wiki.

    To read it, follow this link.
    What do you think the cookie monster eats ?

  7. #7
    mudtel is offline Sugar Community Member
    Join Date
    May 2008
    Posts
    13

    Default Re: HowTo build related dropdowns in Sugar 5.0.0b

    Hi, I followed exactly the steps to include the dynamic dropdown on the Cases edit page.
    However, the page doesnt include the .js file.
    Is it different for Cases module?

    Thanks in advance

  8. #8
    DragonflyMaster is offline Sugar Community Member
    Join Date
    Dec 2007
    Location
    Rimini, Italy
    Posts
    1,421

    Default Re: HowTo build related dropdowns in Sugar 5.0.0b

    Quote Originally Posted by mudtel
    Hi, I followed exactly the steps to include the dynamic dropdown on the Cases edit page.
    However, the page doesnt include the .js file.
    Is it different for Cases module?

    Thanks in advance
    Hi mudtel,
    Cases module does not have a default .js file so you have to create it and put it in modules/Cases/ then include it.
    What do you think the cookie monster eats ?

  9. #9
    mudtel is offline Sugar Community Member
    Join Date
    May 2008
    Posts
    13

    Default Re: HowTo build related dropdowns in Sugar 5.0.0b

    Hi DragonFly,
    Thank you so much for this!! It is working now. I was editing and troubleshooting on the custom/working folder instead of the main custom folder. darnnnnnnnn

    But so glad it worked. You are the man !!!!

  10. #10
    DragonflyMaster is offline Sugar Community Member
    Join Date
    Dec 2007
    Location
    Rimini, Italy
    Posts
    1,421

    Default Re: HowTo build related dropdowns in Sugar 5.0.0b

    Quote Originally Posted by mudtel
    Hi DragonFly,
    Thank you so much for this!! It is working now. I was editing and troubleshooting on the custom/working folder instead of the main custom folder. darnnnnnnnn

    But so glad it worked. You are the man !!!!
    Good to know you have it working now...
    Enjoy the development!!
    What do you think the cookie monster eats ?

Page 1 of 9 12345 ... LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. HELP - Act import (field mapping)
    By smelamed in forum Help
    Replies: 32
    Last Post: 2010-12-15, 05:39 PM
  2. HOWTO - Hack Sugar to support related module info in subpanel (one-many)
    By kenneth.thorman in forum Developer Tutorials
    Replies: 35
    Last Post: 2008-06-10, 07:51 AM
  3. Replies: 6
    Last Post: 2008-03-05, 07:09 PM
  4. Replies: 0
    Last Post: 2005-04-20, 04:55 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
  •