[Question] Best way to include JavaScript Libraries?

hello friends

I am using the hooks.py app_include_js to include javascript libraries to use them with several doctypes and that works fine, but this also produce bugs in the ERPNext functionality.
so how to avoid this conflicts with other libraries, maybe using RequireJS ?

Can u share code?

sure

inside hooks.py i do
app_include_css = [“/assets/addons/css/elevateZoom.js”]

for example this js library it work fine in a doctype with HTML docfield with image element like this:
$(‘#myImg’).elevateZoom();

but sometimes when i open other doctypes in different module i can see the zoom dialog bugged :anguished:

is there anyway to include js files inside the targeted doctype only ?

try include into doctype.js file if it is a external app doctype …or add a custom script for the desired doctype.

2 Likes

do app_include_js
not app_include_css

1 Like

JoEz, is this mean that i have to edit the core doctype.js or create on inside my custom app and if so in which folder should be placed in?

Sagar_Vore, sorry its js really but i wrote it wrong in this topic :laughing:

Since it’s core, I recommend to copy all content of script and paste it into “Custom Script” and select relevant doctype.

1 Like

i think this can be solution How Can i add app_include_js for Single DocType?

but unlike rmehta posted, this method require second argument ‘callback’. im not sure how to impalement but i will check it.

You could use this on frappe.ui.form.on:
jQuery.getScript() | jQuery API Documentation

2 Likes

thanks @Sagar_Vora just like what i want, including scripts in single doctype :slight_smile:

1 Like

I’m not getting urtis point …i’m not saying to hack core code (doctype.js)…but to add you code to yourdoctype.js …or put it in custom scripts …