Search code examples
sugarcrmsuitecrm

In suiteCRM how does one get about changing the Address field country and state text fields to be dropdowns?


I am developing a custom suite CRM module however I find the Address field limiting since it uses text fields for country and state fields.

I have tried researching it by following instructions on this site:

https://johndopenotes.wordpress.com/2013/01/08/sugarcrm-change-address-state-and-country-to-dropdown-menu/

However I am stuck at step 5 since my custom module does not have a metadata directory???

  1. Go to /custom/modules/Leads/metadata and update editviewdefs.php. Look for this code:

    array ( 'name' => 'primary_address_street', 'hideLabel' => true, 'type' => 'Address', 'displayParams' => array ( 'key' => 'primary', 'rows' => 2, 'cols' => 30, 'maxlength' => 150, ), ), 1 => array ( 'name' => 'alt_address_street', 'hideLabel' => true, 'type' => 'Address', 'displayParams' => array ( 'key' => 'alt', 'copy' => 'primary', 'rows' => 2, 'cols' => 30, 'maxlength' => 150, ), ),

and update the type from Address to CustomAddress

array (
            'name' => 'primary_address_street',
            'hideLabel' => true,
            'type' => 'CustomAddress',
            'displayParams' => 
            array (
              'key' => 'primary',
              'rows' => 2,
              'cols' => 30,
              'maxlength' => 150,
            ),
          ),
          1 => 
          array (
            'name' => 'alt_address_street',
            'hideLabel' => true,
            'type' => 'CustomAddress',
            'displayParams' => 
            array (
              'key' => 'alt',
              'copy' => 'primary',
              'rows' => 2,
              'cols' => 30,
              'maxlength' => 150,
            ),
          ),

Can someone please give me a pointer as to how I can make address field in my custom module dropdowns instead of text fields?


Solution

  • Instead to choosing Address type field you can use combination of multiple fileds. For an example for street address you can use (datatype:textField)

    enter image description here

    Similarly for city you can add a text filed. Now for state and country you can use dropdown and add dropdown list as per your need

    enter image description here

    And for zipcode you can use integer / text field as per your requirement.

    Now to make state dependend to country you can use custom javascript / jquery in following way

    1. Add a reference to the javascript file you are going to add at the end of custom/modules/<>/metadata/[edit|detail]viewdefs.php $viewdefs['Opportunities']['EditView']['templateMeta']['includes'] = array ( array ( 'file' => 'path/to/file/filename.js', ), );
    2. Add the javascript file you want to include into the location you referenced above.
    3. Quick Repair from the admin section, then browser refresh