Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
10582 Widoki

 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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

Hello,

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
cze 23
2923
0
gru 17
5952
0
maj 17
8566
0
lip 24
1318
1
lip 24
2008