SetVisibility
Overview
The SugarLogic SetVisibility
action, located in ./include/Expressions/Actions/VisibilityAction.php
, is used to determine the visibility logic of a field based on a formula.
Implementation
While the dependency metadata for your module can be defined in ./modules/<module>/metadata/dependencydefs.php
and ./custom/modules/<module>/metadata/dependencydef.php
, it is recommended to use the extension framework when customizing stock modules to prevent third party plugins from conflicting with your customizations. The following section will demonstrate how to implement a read-only dependency.
SetVisibility Parameters
Parameter | Type | Description |
target | String | The name of the field to target for visibility. |
value | String |
This parameter can accept a boolean formula or |
For more information on the various parameters in the dependency definitions, please refer to the dependency actions documentation.
Examples
The follow sections outline the various ways this dependency can be implemented.
SetVisibility Dependency Extensions
For our example, we will create a dependency on the Accounts module that shows the phone_alternate
field when the phone_office
field has been populated. An example is shown below.
./custom/Extension/modules/<module>/Ext/Dependencies/custom_phone_alternate.php
<?php
$dependencies['Accounts']['phone_alternate_hide'] = array(
'hooks' => array("edit"),
'triggerFields' => array('phone_office'),
'onload' => true,
//Actions is a list of actions to fire when the trigger is true
'actions' => array(
array(
'name' => 'SetVisibility',
'params' => array(
'target' => 'phone_alternate',
'value' => 'not(equal($phone_office,""))',
),
),
),
);
Once you have the file in place, you will need to navigate to Admin > Repairs > and run a Quick Repair and Rebuild.
Note: It is important that the module name is plural ('Accounts' vs. 'Account') and that the name of the dependency, "phone_alternate_hide" in this example, is unique.
Visibility Dependencies in Field Definitions
Unlike several of the other dependencies, SetVisibility
is built into Studio. So this dependency can be set as a custom vardef value or in the varefs file for a new module. If you wanted to add this dependency to an existing field then you could add a file to ./custom/Extension/modules/<module>/Ext/Vardefs/
. An example is shown below.
To accomplish this, we will create an extension in ./custom/Extension/modules/Accounts/Ext/Vardefs/
.
./custom/Extension/modules/Accounts/Ext/Vardefs/phone_alternate.php
<?php
$dictionary['Account']['fields']['phone_alternate']['dependency']='not(equal($phone_office,""))
Next, you will need to navigate to Admin > Repairs > and run a Quick Repair and Rebuild. Once that is done, you can enter a value into phone_office
and the phone_alternate
field will show up once you tab out of the phone_office
field. If you were coding a custom module with new fields, then you would just include it in the modules vardefs.php
file as shown below
<?php
$dictionary['myModule'] = array(
...
'fields' => array(
...
'phone_alternate' => array(
'name' => 'phone_alternate',
'vname' => 'LBL_PHONE_ALTERNATE',
'type' => 'varchar',
'len' => 10,
'dependency'=> 'not(equal($phone_office,""))',
'comment' => 'Other Phone Number',
'merge_filter' => 'enabled',
),
...
)
...
);