Skip to Content
Menu
This question has been flagged
2 Replies
9611 Views

 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
Discard
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
Discard
Best Answer

Hello,

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

Avatar
Discard
Related Posts Replies Views Activity
1
Jun 23
1592
0
Dec 17
4776
0
May 17
7843
0
Jul 24
225
1
Jul 24
408