Reputation: 320
So I have a custom field which is basically a Bool field that hides and shows a dropdown. This is not just one custom field. I made a Field Type like Dynamicenum or Address so i can manage it via Studio. Until now i had my js code (to hide and show) inside the EditView.tpl
.
What is the right way to add JS code to my field?
Thanks in advance
Velrest
Upvotes: 3
Views: 3944
Reputation: 3293
A. if you want to apply it on field whenever it get added to any view of any module then add your JS file in field definition. Path will be like this: custom/include/SugarFields/Fields//EditView.tpl and code will be like following:
<script type="text/javascript" src='{sugar_getjspath file="custom/include/SugarFields/Fields/<your_field_type>/js_file_name.js"}'>
</script>
B. if you want to apply js code in any specific module in specific view then use following sample method:
Add a reference to the javascript file which will be needed for event binding.
Path: custom/modules/Contacts/metadata/editviewdefs.php
Code:
<?php
$viewdefs['Contact']['EditView']['templateMeta']['includes'] =
array (
array (
'file' => 'custom/modules/Contacts/js/editview.js',
),
);
?>
Add the javascript file you want to include into the location you referenced above(custom/modules/Contacts/js/editview.js).
Quick Repair, then hard refresh your browser. All Done !
Upvotes: 4