Skip to Content
Menu
This question has been flagged
1 Reply
14557 Views

Can anyone give me minimal code so that any method I can override for JS method, I tried this code but it doesn't work for me?

I want to override the method for this line https://github.com/odoo/odoo/blob/12.0/addons/im_livechat/static/src/js/website_livechat_window.js#L65

Here is my code file

odoo.define('poc.test', function(require){

"use strict";
console.log('111XXX');
var WebsiteLivechatWindowXXX = require('im_livechat.WebsiteLivechatWindow');
var LivechatWindowTest = WebsiteLivechatWindowXXX.extend({
events: _.extend(WebsiteLivechatWindowXXX.prototype.events, {
'input .o_composer_text_field': '_onInputX',
}),
/**
* @override
* @param {im_livechat.im_livechat.LivechatButton} parent
* @param {im_livechat.model.WebsiteLivechat} thread
*/
init: function (parent, thread) {
this._super.apply(this, arguments);
this._thread = thread;
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* @override
* @private
* @param {Object} messageData
*/
_postMessage: function (messageData) {
console.log('222XXX');
this._super.apply(this, arguments);
},
_onInputX: function () {
console.log('this.$input.val().length');
console.log(this.$input.val().length);
console.log(this.hasThread());
console.log(this._thread);
console.log(this._thread.hasTypingNotification());
},
});
return LivechatWindowTest;
});


In the console, I can see the log '111XXX' which confirm the JS custom code is loaded but when I tried to send message It doesn't print '222XXX' in the console. Also, If I type anything I got an error message in the console which say 'Error: Couldn't find method '_onInputX' in widget'.
I have included in JS file by creating template view and the template inherit 'inherit_id="website.assets_frontend"' and also I have added depends 'im_livechat' in __manifest__.py file.

Avatar
Discard
Best Answer

this widget should be overridde with `include` rather than `extend` because you are not creating any instant of extended widget

WebsiteLivechatWindowXXX.extend({ ==> WebsiteLivechatWindowXXX.include({
Avatar
Discard
Author

Thanks, it works.

Do you know any tutorial/Book other than Odoo docs where I can learn JS framework used in Odoo? I am struggling to understand JS.

Please @ sah Vinay, have you gotten any resource in regards to this?

i am also struggling to understand odoo javascript framework...plz any tutorial/book

Related Posts Replies Views Activity
1
Apr 21
3178
1
Apr 20
2136
0
Mar 20
1360
1
Feb 20
2829
1
Aug 19
5651