Select event error

Hi,
I want to handle a click event when user select one of the options in the selected field(category), and i use these statements
cur_frm.fields_dict.category.input.on(“click”, function(evt){
get_cost_assignment(cur_frm);
refresh_field(“cost_assignment”);

});

but i have the following error
Uncaught TypeError: Cannot read property ‘on’ of undefined
at eval (eval at setup (form.min.js:2642), :247:35)
at Class.setup (form.min.js:2642)
at _f.Frm.setup (form.min.js:213)
at _f.Frm.refresh (form.min.js:536)
at Class.load (form.min.js:97)
at form.min.js:82
at Object.callback (desk.min.js:5967)
at Object.callback [as success_callback] (desk.min.js:1307)
at 200 (desk.min.js:1332)
at Object. (desk.min.js:1422)
(anonymous) @ VM1295:247
setup @ form.min.js:2642
_f.Frm.setup @ form.min.js:213
_f.Frm.refresh @ form.min.js:536
load @ form.min.js:97
(anonymous) @ form.min.js:82
callback @ desk.min.js:5967
callback @ desk.min.js:1307
200 @ desk.min.js:1332
(anonymous) @ desk.min.js:1422
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
z @ jquery.min.js:4
(anonymous) @ jquery.min.js:4

You can use the following code:

frappe.ui.form.on('Doctype Name', {
	field_name: function(frm) {
             frappe.events.other_field_name(frm);
	},
        other_field_name: function(frm) {
        }
});

frappe.ui.form.on creates event handler for all the docfield of that particular doctype

1 Like

@MaysaaSafadi,

for click event on form field you will need the use the $input instead of input.

e.g.

cur_frm.fields_dict.cost_center.$input.on('click', function(event){
	// your code after click event
})
1 Like

Thanx @makarand_b