Help

2

Odoo 11: How to define a Form View Custom Widget in odoo 11

Avatar
Bréndou Serge Eric

Hello everyone! I used to define custom form widgets in odoo 10 as follow: 

var core = require('web.core');
var form_common = require('web.form_common');
var MyWidget = form_common.FormWidget.extend({
init: function (parent, object) {
console.log('INIT!!!');
this._super.apply(this, arguments);
},
start: function () {
         //codes
},
events: {
"click button.ct_button_filter": "open_search_dialog",
},
open_search_dialog: function () {
//codes...
},
display_filter: function () {
//codes...
},
});

core.form_custom_registry.add(
'my_widget', MyWidget
);

and invoke it in this way:
...<page string="Details..."><widget type="my_widget"> </page>.....
This perfectly works in odoo 10; but in 11, I get this error: Widget is not a constructor.
Do you have any idea guys?

Avatar
Discard
2 Answers
2
Avatar
Bréndou Serge Eric
Best Answer

Thanks Suraj! I found how to do it; i'm using  web.Widget instead.

var core = require('web.core');
var Widget= require('web.Widget'); var widgetRegistry = require('web.widget_registry'); var FieldManagerMixin = require('web.FieldManagerMixin');
var MyWidget = Widget.extend(FieldManagerMixin, {
init: function (parent, model, state) {
this._super(parent); FieldManagerMixin.init.call(this); // init code here
},
start: function () {
         //codes
},
events: {
"click button.ct_button_filter": "open_search_dialog",
},
open_search_dialog: function () {
//codes...
},
display_filter: function () {
//codes...
},
});

widgetRegistry.add(
'my_widget', MyWidget
);
On the form side i call it this way <widget name="my_widget"/> 
2 Comments
Avatar
Discard
Avatar
sibi0229
-

Hi guys kindly give me an information about how to call this widget in xml side with some detail information hope it will help me a lot

Avatar
Rohit Pandey
-

How can i place Odoo control pannel in custom widget @Bréndou Serge Eric

0
Avatar
Suraj Shukla (suh)
Best Answer

Hello, you can do it as follows:

var FormView = require('web.FormView');

var MyWidget = FormView.extend({

  template: "your template name",

events: {

//events here

}

//functions for widge 

});

return MyWidget;

Avatar
Discard