for example: when a field value changed , I want to do something in the onchange event of the element.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
3
Replies
2143
Views
odoo.define('hx_tsl.autosave',function(require){
"use strict";
var FormController= require('web.FormController');
console.log("enter");
FormController.include({
events: {
'change #is_return': '_onChange',
},
_onChange: function (event) {
console.log("value changed!")
},
}
});
})
it seems does not work in odoo16 community edition. "enter" was printed,but "value changed" not printed.
Create a new module or identify the existing module where you want to add the custom JavaScript code.
Inside your module, create a new JavaScript file, let's call it custom_script.js, and add your custom JavaScript code in it. For example:
odoo.define('your_module.custom_script', function (require) {
"use strict";
var FormController = require('web.FormController');
var core = require('web.core');
FormController.include({
_onFieldChanged: function (event) {
this._super.apply(this, arguments);
var record = this.model.get(event.target.dataset.recordId);
var fieldName = event.target.name;
#your custom logic based on the changed field value
if (fieldName === 'your_field_name') {
var fieldValue = record.data[fieldName].res_id;
# Perform actions based on the field value change
# ....
}
},
});
});
note;make sure add the js file reference in xml file
Hi,
You need to include your custom event inside form controller.
var FormController = require("web.FormController");
FormController.include({
events: {
'change #any_field': '_onChange',
},
_onChange: function (event) {
//Do what you want
}
});
Regards