Siqi Liu
Siqi Liu

Reputation: 11

Multiselect dependent dropdowns in sugarcrm 7 pro

I am a beginner at Sugarcrm currently and the documentation does not seem to help with the issue. My problem here is that I need to create an dependent droplist from an initial dropdown. So for example, if the initial dropdown was states, you could pick Florida, and then a second drop is a MULTISELECT in which you can select multiple cities in which you are from. I really do not know how to approach this problem. If you guys can help with this problem that would be great thanks!

Upvotes: 1

Views: 1667

Answers (2)

Laurent
Laurent

Reputation: 601

You can do this by custom code. First, create a file 'fields.php' in /custom/Extension/modules/{YourModuleMulti}/Ext/Vardefs/. In that file, add the following code:

<?php

$dictionary['{YourModuleSingle}']['fields']['states'] = array(
    'name' => 'states',
    'vname' => 'LBL_STATES',
    'required' => true,
    'reportable' => true,
    'audited' => true,
    'importable' => false,
    'massupdate' => false,
    'default' => '',
    'len' => 200,
    'type' => 'enum',
    'options' => 'enum_states',
);

Above, you created a custom field 'states'. 'enum_states' is the name of your dropdown values. We will add them below.

Create a file 'en_us.enum.php' in /custom/Extension/application/Ext/Language/. There, add the code below (you need to edit it to your needs):

<?php

$app_list_strings['enum_states'] = array(
    'Florida' => 'Florida',
    'Chicago' => 'Chicago',
    '...' => '...',
);

Your first field is ready. You just created a dropdown field 'states'. Now, we need to create a dependent multiselect field cities from states. To do so, open the file 'fields.php' (where you added the states field). In that file, append the next code:

$dictionary['{YourModuleSingle}']['fields']['cities'] = array(
    'name' => 'cities',
    'vname' => 'LBL_CITIES',
    'required' => false,
    'reportable' => true,
    'audited' => true,
    'importable' => false,
    'massupdate' => false,
    'len' => 255,
    'type' => 'multienum',
    'isMultiSelect' => true,
    'options' => 'enum_cities',
);

$dictionary['{YourModuleSingle}']['fields']['cities']['labelValue'] = 'Cities';
$dictionary['{YourModuleSingle}']['fields']['cities']['visibility_grid'] = array(
    'trigger' => 'states',
    'values' => array(
        '' => array(),
        'Florida' => array(
            'a city',
            'a next city',
            '...',
        ),
        'Chicago' => array(
            'another city',
            '...',
        ),
    ),
);

That's all. Now you can add these fields to your views. Don't forget to add the labels and replace {YourModuleSingle} to a single module name. For example 'Account'. {YourModuleMulti} = 'Accounts'.

If you have eny further question. Feel free to ask ;-)

Upvotes: 2

Hakulukiam
Hakulukiam

Reputation: 379

The Visibility Editor in Field Creation is what you seek.

Drag the options you want to see into the selection when you want them to see. In this case if Blank is selected in Type, Disabled becomes avaliabe in Elastic_boosts_options

See Image:

Studio

Upvotes: 0

Related Questions