user3410640
user3410640

Reputation: 91

SugarCRM field visibility depends on dropdown field value

I need to show/hide some fields based on selected value of dropdown field in edit view of a custom module. SugarCRM CE version is 6.1.4.

I'm trying with:

$dictionary['<module name>']['fields']['<hidden field>']['dependency'] = 'equal($<trigger field>, "<trigger field value>")';

But it doesn't work for me. Any suggestion is welcome.

Thanks in advance

Upvotes: 2

Views: 2430

Answers (2)

osk
osk

Reputation: 311

I'm not so sure the CE-version supports using SugarLogic - only Pro & Enterprise do as far as I know. Other than that, your original code looks fine!

For future references though, here's an example of how to properly use dependencies: http://support.sugarcrm.com/02_Documentation/04_Sugar_Developer/Sugar_Developer_Guide_6.7/03_Module_Framework/Sugar_Logic/02_Using_Sugar_Logic_Directly/Creating_a_custom_dependency_using_metadata/

List of available actions: https://support.sugarcrm.com/02_Documentation/04_Sugar_Developer/Sugar_Developer_Guide_6.7/03_Module_Framework/Sugar_Logic/01_Dependencies/

Upvotes: 0

user3410640
user3410640

Reputation: 91

I solved it with javascript code. In modules/module/metadata/editviewdefs.php

    'templateMeta' => 
    array (
    ....
'includes'=> 
        array(
            array('file'=>'modules/<module>/ShowHidePanel.js'),
    ),
    'javascript' => '<script type="text/javascript" language="Javascript">showHidePanel();</script>',
...


    array (
            'name' => 'geometria',
            'studio' => 'visible',
            'label' => 'LBL_GEOMETRIA',
            'displayParams' =>
           array (
             'javascript' => 'onchange=showHidePanel();',
           ),
          ),

and created file modules/module/ShowHidePanel.js

function showHidePanel() {
    if(document.getElementById('geometria').value == 'pletina') {
        document.getElementById('LBL_EDITVIEW_PANEL1').style.display = 'initial';
        document.getElementById('LBL_EDITVIEW_PANEL2').style.display = 'none';
        document.getElementById('LBL_EDITVIEW_PANEL3').style.display = 'none';
        document.getElementById('LBL_EDITVIEW_PANEL4').style.display = 'none';
        document.getElementById('LBL_EDITVIEW_PANEL5').style.display = 'none';
    }else if(document.getElementById('geometria').value == 'redondo') {
        document.getElementById('LBL_EDITVIEW_PANEL1').style.display = 'none';
        document.getElementById('LBL_EDITVIEW_PANEL2').style.display = 'initial';
        document.getElementById('LBL_EDITVIEW_PANEL3').style.display = 'none';
        document.getElementById('LBL_EDITVIEW_PANEL4').style.display = 'none';
        document.getElementById('LBL_EDITVIEW_PANEL5').style.display = 'none';
    }

}

Upvotes: 1

Related Questions