When during the form life-cycle does frappe.require execute the script?


I’m trying to move as much as possible of a Form Script from the WUI Script window into a script file and then execute it with frappe.require().

Using the User doctype, it’s working as expected.

Here’s the script.js file

frappe.ui.form.on('User', {
	refresh: function(frm) {
	validate: function(frm) {

I then call this file in the WUI Form Script window with this



The initial refresh is triggered when the form loads along with any subsequent validation events


However for the initial refresh event on a Custom doctype it does not trigger, only the subsequent validation and refresh after clicking the Save button.


Why is this the case? And more importantly, is using frappe.require the correct way of moving all the Form script logic to a file?

why dont you use app_include_js or doctype_include_js and add the custom js files to your app ( assuming you have a custom app )

Thanks @neerajvkn

That’s the problem, it’s not a custom app. I’m simply customising the default app by adding a few additional doctypes and a bit of client-side code.

my suggestion would be to create a custom app and add your files there, that way you will have more control over it. like version control / portability of your scripts.

1 Like