I want to add a JS to run for all doctypes as if there is a Form event of “onload”.
I put the JS path into the hooks.py file, but I don’t know how to do the later.
Please help.
Hi @abrefael:
Try this:
On hooks.py
app_include_js = "/assets/your_app/js/your_file.js"
On your_file.js
frappe.after_ajax(() => {
if (frappe.ui && frappe.ui.form) {
frappe.ui.form.on("*", {
refresh: function(frm) {
console.log("I am here. Where are you?");
}
});
}
});
Hope this helps.
1 Like
Thank @avc ,
I am not sure I did it right (or perhaps explained myself well).
I open a form for a doctype, let’s say: /app/ideas/a good idea
.
I can see the “a good idea”.
However, in the console, nothing.
I tried:
console.log('before');
frappe.after_ajax(() => {
console.log('begin');
if (frappe.ui && frappe.ui.form) {
frappe.ui.form.on("*", {
refresh: function(frm) {
console.log('after if');
}
});
}
console.log('end');
});
console.log('after');
Now, “Ideas” is in one custom app while the new js file is in a newly installed app. Is this related to my difficulties?
Hi @abrefael:
Tried with custom app, it’s working. Check:
JS File name and path
Restart bench (if you are in production mode)
Clear browser cache
Any error in console?
Check Sources tab on browser dev console, is your file there?
1 Like
It worked.
Probably a refreshing thing…
Thank you