JS function always trigger when page refresh and load

frappe.ui.form.on(“Expense Claim”, {
//all functions here are called on page refresh and load?
currency: function(frm){
//this function is called every time page load and refresh, why?
}

});

you have added a trigger to currency field.

when you change the value of currency field, the system executes function.

How can I prevent this function called when page load or refresh?

Example:

frappe.ui.form.on("Expense Claim", {
    refresh: function(frm) {
        frm.events.operation_on_currency_change(frm);
    },
    
    onload: function(frm) {
        frm.events.operation_on_currency_change(frm);
    },
    
    currency: function(frm) {
        frm.events.operation_on_currency_change(frm);
     },
     
     operation_on_currency_change: fucntion(frm) {
         // your code
     }
    
})

1 Like

VM874:271 Uncaught (in promise) TypeError: frm.events.operation_on_currency_change is not a function
at currency (eval at setup (form.min.js:2616), :271:14)
at runner (form.min.js:2555)
at form.min.js:2570
at

Sorry, It’s my misspelling. Your code works but It’s not what i want.

My problem is:
I don’t want function operation_on_currency_change execute when page load or refresh.
I don’t call or trigger this function in refresh, I call only in currency function but it always execute when page refresh or reload.

currency: function(frm){
//this function always trigger event onChange as it’s currency list which automated assigned value (“USD”) on page load. I want event onChange happen when only user change value.
}

then you can put function with the field name like

currency: (frm,cdt,cdn){
// your code
}