Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

publicWidget.Widget.extend example

Avatar
odoo
Avatar
Discard
1 Answer
0
Avatar
odoo
Best Answer

I figured out: selector is not enough to make publicWidget work on website. 

It just create an istance of the widget for each element matched by the selector but then you need to render the widget to make use of it. One way to achieve this task is by using the following code to initialize, render, and put the widget in the DOM:

*     var myWidget = new MyWidget(this);
* myWidget.appendTo($(".some-div"));

The following snippet works well in the website

odoo.define("idro_portal.my_account_extend", function (require) {
"use strict";

var core = require('web.core');
var publicWidget = require('web.public.widget');

publicWidget.registry.PublicWidgetMyAccountExtend = publicWidget.Widget.extend({
selector: '.custom_public_widget_extend',

start: function () {
var res = this._super.apply(this, arguments);
this.do_notify('Success', 'Widget start notify');
return res
},
});
var PublicWidgetMyAccountExtend = new publicWidget.registry.PublicWidgetMyAccountExtend(this);
PublicWidgetMyAccountExtend.appendTo($(".custom_public_widget_extend"));
return publicWidget.registry.PublicWidgetMyAccountExtend;
});


Avatar
Discard