Has anyone known about custom_events in Odoo 12 javascript? also how to call or trigger a custom_events?
example\ https://github.com/odoo/odoo/blob/12.0/addons/web/static/src/js/fields/basic_fields.js#L153
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Has anyone known about custom_events in Odoo 12 javascript? also how to call or trigger a custom_events?
example\ https://github.com/odoo/odoo/blob/12.0/addons/web/static/src/js/fields/basic_fields.js#L153
Odoo has a custome_event the same HTML as the DOM event.
The difference is DOM event bubble up through DOM nodes while odoo custom_event bubble up thought odoo inheritance (parent/child widget) chain.
The main purpose of the custom_events is widget decupling (loos binding) so there is no hardcoded dependency between child to parent and the widget can move around freely while structure change. child widget just triggers custom_event and it's parents responsibility to listen to an event and react upon it.
Before custom_event there are several instances where a child call parent using ugly code like this.get_parent().get_parent().call_method()
Post here if you need an example or more explanation
===================
`field_change` custom_event trigger_up from here
var GrandParentWidget = Widget.extend({
custom_events: {
my_custom_event : '_onMyCustomEvent',
},
_onMyCustomEvent: function(ev) {
console.log('event triggred', ev.data)
}
})
var ParentWidget = GrandParentWidget.extend({
.......
})
var ChildWidget = ParentWidget.extend({
'click .my_link': '_onLinkClick'
_onLinkClick: function () {
this.trigger_up('my_custom_event', {data: {}}
}
})
In the above example ChildWidget trigger_up`my_custome_event' and it will listen by GrandParent up in the inheritance chain.
Thanks for answering
So, if the class has custom_events like:
custom_events: _.extend({}, DebouncedField.prototype.custom_events, {
field_changed: '_onFieldChanged',
}),
I still confuse how and when the event is fired
I have update the answer
Oh I see. Thank you very much Ravi. It's very clear explanation
Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!
DaftarPost Terkait | Replies | Tampilan | Aktivitas | |
---|---|---|---|---|
|
0
Okt 18
|
3995 | ||
|
0
Okt 18
|
7413 | ||
|
3
Des 23
|
30639 | ||
How to override js method in Odoo? [Odoo 12]
Diselesaikan
|
|
1
Mei 21
|
15773 | |
|
1
Apr 21
|
4423 |