Problem
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:
https://www.dropbox.com/s/ml7u08lz606bp85/one2many_customwidget_view.png?dl=0
Edit mode:
https://www.dropbox.com/s/4ttq70lbnrbf8zi/one2many_customwidget_edit.png?dl=0
(image embedding is currently not working for me)
Code
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"?>
<templates>
<t t-name="FieldManagerState">
<span t-att-class="'oe_form_field '+widget.widget_class"
t-att-style="widget.node.attrs.style">
<i class="fa fa-eye" style="font-size: 1.5em; line-height: 28px; padding-left: 5px;"/>
</span>
</t>
</templates>
Do you have any idea how to render the widget in the view mode correctly (same as in the edit mode).