It will be done by below steps only! Lets do this,
STEP 1 : Add a reference to the JavaScript file which will be needed for event binding.
Path: custom/modules/<desired_module>/metadata/editviewdefs.php
<?php
$viewdefs['<desired_module>']['EditView']['templateMeta']['includes'] =
array (
array (
'file' => 'custom/modules/<desired_module>/js/editview.js',
),
);
?>
Step 2 : Add the JavaScript file you want to include into the location you referenced above(custom/modules/<desired_module>/js/editview.js).
Step 3 : Write your custom function code in editview.js file.
Step 4 : Now the filed in which you want to call the JavaScript function write as follow
0 =>
array (
'name' => 'fieldname',
'studio' => 'visible',
'label' => 'LBL_',
'displayParams' =>
array (
'javascript' => 'onchange=functionname()',
),
),
or
0 =>
array (
'name' => 'fieldname',
'studio' => 'visible',
'label' => 'LBL_',
'displayParams' =>
array (
'field'=>
array(
'onclick' => 'functionname();',
),
),
),
Step 4 : Quick Repair, then hard refresh your browser. All Done !
Step 5 : Done! Refresh the page and start testing.
Note :
1. Read the comments in code carefully and replace the variables as asked.
2. Here, <desired_module> means the module name you see in the URL, for example, Contacts, Leads, Accounts, etc.
3. You may find the field names and its labels in Admin > Studio > <Your_module> > Fields > <Choose correct field> > Take Field Name and System Label.
Hope you find this blog post helpful.
Feel free to add comments and queries, that helps us to improve the quality of posts.
You can contact us at info@infotechbuddies.com
Thank you.