ReadOnly action, located in
./include/Expressions/Actions/ReadOnlyAction.php, is used to determine if a field is editable or not based on a formula.
While the dependency metadata for your module can be defined in
./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.
|target||String||The name of the field to make read only.|
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.
For our example, we will create a dependency on the Accounts module that makes the
name field read-only when the
lock_record_c field has been checked. The first step is to create the
lock_record_c checkbox field in Studio and add it to your Record View layout. When this checkbox is checked, we will make the name field read-only. Our example extension definition is shown below:
<?php $dependencies['Accounts']['readonly_fields'] = array( 'hooks' => array("edit"), 'trigger' => 'true', //Optional, the trigger for the dependency. Defaults to 'true'. 'triggerFields' => array('lock_record_c'), 'onload' => true, //Actions is a list of actions to fire when the trigger is true // You could list multiple fields here each in their own array under 'actions' 'actions' => array( array( 'name' => 'ReadOnly', //The parameters passed in will depend on the action type set in 'name' 'params' => array( 'target' => 'name', 'value' => 'equal($lock_record_c,true)', ), ), ), );
Once you have all the files 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, "readonly_fields" in this example, is unique.
In some scenarios, you may want a specific field to always be read-only. To accomplish this, you can modify the
'value'attribute to always be "true". Given the above example, you would modify:
'value' => 'equal($lock_record_c,true)',
'value' => 'true',
Last modified: 04/25/2018 11:25pm