Weird Interaction on script field triggered twice in erpnext v14.27.1

When I write a custom script for any field, for example, when I put a customer in the sales invoice, immediately the trigger runs, then when I click outside the customer field, it triggers it again.

frappe.ui.form.on('Sales Invoice', {

    "customer":function(frm){
console.log("Agewge")
    }
})

So when I select the customer, the console will print Agewge then when I click outside, the console again will print Agewge

I don’t know if it is a bug or what, but I use erpnext v14.27.1 , frappe v14.39.0 and Frappe HR: v15.0.0-dev

Hi @MAHMOOD_EBRAHIM,

No No,

It is not a bug, but rather the expected behavior when using custom scripts for fields. When you write a custom script for a field, it attaches an event computing to that field. This computing triggers whenever there is a change in the field’s value or when the field loses focus (in your case when you click outside the customer field).

Thank You!

Thank you for your replay, and sorry for the late response

But why is this behaviour not working like this on the old version, like V13.36.2?
And is it logical to run the code twice in every custom trigger?
So in v14, we cannot use a field trigger because it is registered with two events?

Also, for more information, this behaviour works only on the Links type, but it normally works in the Data type (only triggered when the value change)