Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Custom form widget in one2many field doesn't render

on 9/30/15, 3:20 AM 1,284 views


I created a custom form widget to render an icon to represent the states of an selection field. This field and widget is used in a one2many field/widget. The problem is now that it just works if you are editing the line of the one2many field. If you are just viewing the form without editing only the id of the selection field is shown as text.

View mode:


Edit mode:


(image embedding is currently not working for me)


Java Script

    instance.web.form.widgets.add('managerstate', 'instance.web.form.FieldManagerState');

instance.web.form.FieldManagerState = instance.web.form.FieldChar.extend({
template: 'FieldManagerState',
widget_class: 'oe_form_field_managerstate',
render_value: function () {
if (this.get('value') == 'email_sent') {
this.$el.find('i').css('color', 'blue');
} else if (this.get('value') == 'activated') {
this.$el.find('i').css('color', 'red');

Qweb XML

<?xml version="1.0" encoding="UTF-8"?>
<t t-name="FieldManagerState">
<span t-att-class="'oe_form_field '+widget.widget_class"
<i class="fa fa-eye" style="font-size: 1.5em; line-height: 28px; padding-left: 5px;"/>

Do you have any idea how to render the widget in the view mode correctly (same as in the edit mode).

On 10/21/15, 8:08 AM

I found the solution:

For the list view (i.e. also in x2many fields) you have to write an own widget renderer class. It is important which name the name/id after the add() function has. Here an extract of the comment in the code (you can find it in addons/web/static/src/js/view_list.js):

* Registry for column objects used to format table cells (and some other tasks
* e.g. aggregation computations).
* Maps a field or button to a Column type via its ``$tag.$widget``,
* ``$tag.$type`` or its ``$tag`` (alone).

Java Script

    instance.web.list.columns.add('field.managerstate', 'instance.web.list.Managerstate');

instance.web.list.Managerstate = instance.web.list.Column.extend({
_format: function (row_data, options) {
var value = row_data[this.id].value;
// do something
var style = 'red';
return QWeb.render('FieldManagerState.cell', {
'style': style,

Qweb XML

 <t t-name="FieldManagerState.cell><button type="button"><i class="fa fa-eye" t-att-style="style"/></button></t>

In this example I reduced the code to show how it works. It doesn't contains all the logic of the question. But as you maybe see you have to do the same logic as in the question (depends on how it works/looks like in the read, edit mode in the list or without list.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 9/30/15, 3:20 AM
Seen: 1284 times
Last updated: 10/21/15, 8:11 AM