Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
10608 Prikazi

 I'm trying to add custom widget in odoo 10. The new widget is a custom <table> html tag. The color of each <td> depends on a field in my model.

I followed many examples in the internet but I can't get it work.

Please, anyone could help me by giving a basic example in odoo 10.

Avatar
Opusti
Best Answer

Hello,

  1. Create a javascript module like below for your custom field

  2. Create a qweb template for the custom field

  3. You can access all fields on the form like shown below.

  4. Then you can pass the value to the template
    Finally add the field to the form like <widget type="customwidget"/>




The Script


odoo.define('module.module_title', function (require) {

"use strict";


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

var common = require('web.form_common');

var CustomWidget = common.FormWidget.extend({

    template: 'CustomWidget',

     events: {

     

   

    },

   

    start: function() {

      var self=this;

// You can get the values of all fields on the form like this

      var field_value=self.field_manager.get_field_value('field_name');

self.color_class=field_value;

        this._super();

     

    },

  



    })

core.form_custom_registry.add('customwidget', CustomWidget);

return {

  CustomWidget:CustomWidget,




 

};

});


The Template


  <t t-name="CustomWidget">

       

            

<td t-att-style=""  t-att-class="widget.color_class">Some Thig</td>    

       

     

         

      

    </t>


To display the widget on the form view


<widget type="customwidget"/>



Thank You

Avatar
Opusti
Best Answer

Hello,

This module creates a new widget for adding map.You can refer it

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
1
jun. 23
2975
0
dec. 17
5995
0
maj 17
8593
0
jul. 24
1383
1
jul. 24
2197