Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
10263 Vistas

 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
Descartar
Mejor respuesta

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
Descartar
Mejor respuesta

Hello,

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

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
jun 23
2408
0
dic 17
5581
0
may 17
8314
0
jul 24
943
1
jul 24
1377