3

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

Star
  • 3,222
  • 5
  • 32
  • 48
Velrest
  • 300
  • 1
  • 3
  • 18

1 Answers1

4

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:

  1. 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',
        ),
    );
?>
  1. Add the javascript file you want to include into the location you referenced above(custom/modules/Contacts/js/editview.js).

  2. Quick Repair, then hard refresh your browser. All Done !

Star
  • 3,222
  • 5
  • 32
  • 48
  • Where would i put the js file in A? As far as i know SuiteCRM compiles JS code somewhere. – Velrest Nov 06 '17 at 12:28
  • 1
    normally this JS file remain in same folder (or inside js/javascript folder) with tpl file but you can keep file at any location and add proper path in tpl. – Star Nov 06 '17 at 12:30
  • 1
    if you are talking about JS Grouping then that is something else. I think no need to add a file in SuiteCRM js grouping for this. – Star Nov 06 '17 at 12:31
  • how are you supposed to control the order the js is executed in? i want to overwrite functions but this method has the custom js run before the non-custom js – daslicious Mar 08 '19 at 00:43