Skip to Content
Menu
This question has been flagged
3 Replies
2167 Views

I want to create a new clickable many2many widget
for odoo16 


my code is:

odoo.define('my_module.many2many_widget', function (require) {
"use strict";

var core = require('web.core');
var dialogs = require('web.view_dialogs');
var registry = require('web.field_registry');
var rel_fields = require('web.relational_fields');
var _t = core._t;

var FieldMany2ManyTagLinks = rel_fields.FieldMany2ManyTags.extend({
get_badge_id: function (el) {
if ($(el).hasClass('badge')) return $(el).data('id');
return $(el).closest('.badge').data('id');
},
events: _.extend({}, rel_fields.FieldMany2ManyTags.prototype.events, {
'click .badge': function (e) {
e.stopPropagation();
var self = this;
var record_id = this.get_badge_id(e.target);
new dialogs.FormViewDialog(self, {
res_model: self.field.relation,
res_id: record_id,
context: self.record.getContext(),
title: _t('Open: ') + self.field.string,
readonly: !self.attrs.can_write,
}).on('write_completed', self, function () {
self.dataset.cache[record_id].from_read = {};
self.dataset.evict_record(record_id);
self.render_value();
}).open();
}
})
});
registry.add('many2many_tags_links', FieldMany2ManyTagLinks);

return {
FieldMany2ManyTagLinks: FieldMany2ManyTagLinks
};

});


and am getting the following error

TypeError: FormView is not a constructor

How to solve this please?





Avatar
Discard
Author Best Answer

The code in the question worked very well for odoo16,

When it was giving me that error I was testing it on a docker odoo version,

But then I tested it on an actual server and it worked properly

Avatar
Discard
Best Answer
Sorry to bother you but did you solve the problem? or did you archive any solution to make many2many_tags clickable?



Avatar
Discard
Best Answer

It looks like there might be an issue with the line new dialogs.FormViewDialog(self, { in your code. It seems that FormViewDialog is not a constructor.

Based on the documentation for version 16 of Odoo, it looks like FormViewDialog is a subclass of Dialog, which is a class for displaying modal dialogs in the interface. It might be worth trying to replace FormViewDialog with Dialog to see if that resolves the error.

Alternatively, you could try to import FormViewDialog from the web.view_dialogs module and see if that resolves the issue.

I hope this helps! Let me know if you have any further questions.


Avatar
Discard
Author

Thank you very much, but That didn't work