Best means of adding javascript to specific CMS layouts in admin?
For modules I can create JQX Controllers which can help with whatever inputs are in that module. But if I create a custom layout for regular CMS pages, what mechanism can I use to place scripts into such pages, so I can manipulate the custom fields? I noticed there is the js key for fields (as
here), which is great for short scripts, and I suppose that could be used to inject js scripts from elsewhere into the page - but am I missing something more obvious?
Comments
The first would be to create a custom field type to handle it:
http://docs.getfuelcms.com/general/forms#association_parameters
I've found this method good for reusable form elements.
For more one off elements, I use the "js" parameter on a field like you suggested. The value can be a string value to the name of a javascript file, or maybe easier for shorter scripts, you can just use the "script" tag as the value and then use simple jQuery like so:
...'js' => '<script>$(function(){ ... your custom code here })</script>', ...
I tend to use this method a lot since I don't like creating separate javascript files to manage form element stuff for one of elements.
I noticed also that there is $config['fuel_javascript'] in Fuel.php / My_Fuel too for more widespread stuff.