This question has been flagged

Dear all,


I want to create a many2many_tags widget with a custom tooltip. Because by default it is the 'display_name' of the tag, which is already shown on the tag. 


After some investigation I started adding the functionality to the many2many_tag instead of creating a new widget and I tried to mimic the behavior of the color_field. For the color of the tag, you specify an option "...'color_field':'color'..." in the view, so I thought about adding "... 'tooltip_field':'x_tooltip'..." (or so).

Here is my code, hopefully someone finds the issue.

JS tooltip

odoo.define('many2many_tags_tooltip.widget', function(require) {
"use strict";
var registry = require('web.field_registry');
var relational_fields = require('web.relational_fields');
relational_fields.FieldMany2ManyTags.include({
tag_template: 'FieldMany2ManyTagsTooltip',
init: function () {
this._super.apply(this, arguments);
this.tooltipField = this.nodeOptions.tooltip_field;
},
_getRenderTagsContext: function () {
var result = this._super.apply(this, arguments);
result.tooltipField = this.tooltipField;
return result;
},
});
});

XML Template

TAG templates id="template" xml:space="preserve">
TAG t t-name="FieldMany2ManyTagsTooltip">
TAG t t-foreach="elements" t-as="el">
TAG t t-set="color" t-value="el[colorField] || 0"/>
TAG t t-set="tooltip" t-value="el[tooltipField] || el.display_name"/>
TAG t t-set="colornames" t-value="['No color', 'Red', 'Orange', 'Yellow', 'Light blue', 'Dark purple', 'Salmon pink', 'Medium blue', 'Dark blue', 'Fushia', 'Green', 'Purple']"/>
TAG div t-attf-class="badge badge-pill dropdown o_tag_color_#{color}" t-att-data-color="color" t-att-data-index="el_index" t-att-data-id="el.id" t-attf-title="#{tooltipField}">
TAG t t-set="_badge_text">
TAG span class="o_badge_text">
TAG span role="img" t-attf-aria-label="Tag color: #{colornames[color]}"/>
TAG t t-esc="el.display_name"/>
TAG /span>
TAG /t>
TAG /div>
TAG /t>
TAG /t>
TAG /templates>
(sorry - XML is always removed from my post, that's why I replaced < by TAG)

The options of the many2many tag are: options="{'color_field': 'color','tooltip_field':'x_tooltip'}" but still the tooltip of the tags show the display_name because the first part of  
t-value="el[tooltipField] || el.display_name"
is false.

When I change the XML a little to show the tooltip_field as tooltip, it works.
 t-attf-title="#{tooltipField}" --> tooltip = 'x_tooltip'

Somehow something with el[tooltipFIield} is wrong, but I cannot find what.
Anyone has a clue?

Jan

Avatar
Discard