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.
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 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)
For anyone interested
we solve this problem by adding force_set_value = (this.doc && this.doc.__run_link_triggers);
In /apps/frappe/frappe/public/js/frappe/form/controls/base_control.js
Inside validate_and_set_in_model(value, e, force_set_value = false)
before if (this.inside_change_event || (is_value_same && !force_set_value)) { return Promise.resolve(); }