Velrest
Velrest

Reputation: 320

SuiteCRM: How do i add JS to my custom Field

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

Answers (1)

Abdur Rehman
Abdur Rehman

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:

  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 !

Upvotes: 4

Related Questions