The base code of your script is executed when the document is loaded. You can make use to the jQuery document ready function to be sure the form is available and then apply your filter.
@lasalesi thanks for your fast reply.
I now already what did you say.
I need help with this :
The base code of your script is executed when the document is loaded. You can make use to the jQuery document ready function to be sure the form is available and then apply your filter.
If you load the js globally, it will execute every time (add a console.log(āā¦ā) to make sure it does). Then, it should be executed on every doctype, and once the form is loaded your function applied. Have a try and let us know if it works as expectedā¦
This script will be executed every time, but how we can make this script will executed only after opening doctype? Is the correct trigger, what is @Mohammed_Redha write in the topic?(frappe.ui.form.on(ā*ā, āonloadā, function(frm) )
// the following two handles will watch the page changes everywhere
$(window).on('hashchange', page_changed);
$(window).on('load', page_changed);
function page_changed(event) {
// waiting for page to load completely
frappe.after_ajax(function () {
var route = frappe.get_route();
if (route[0] == "Form") {
frappe.ui.form.on(route[1], {
refresh: function (frm) {
console.log("doctype =" + frm.doctype);
}
})
}
})
}
The build.json file will allow to build combined js files. This will take one or more of your specified js files and build them into a /asset js file. You can also directly load js, this might get a bit messy in case you have more and more contentā¦
If you want to load java script throughout create JS file in public folder of your app mention the path in build.json try to build you can access code in any js file now for debugging you can try on your browser console as well
frappe.router.on(āchangeā, page_changed) use thisā¦
instead of
$(window).on(āhashchangeā, page_changed);
$(window).on(āloadā, page_changed);