fields
forms
Many2many Tags
Odoo 19 fields — Many2many Tags (views)
Live preview
Interactive
Source excerpt
web/static/src/views/fields/many2many_tags/many2many_tags_field.js
import { _t } from "@web/core/l10n/translation";
import { CheckBox } from "@web/core/checkbox/checkbox";
import { ColorList } from "@web/core/colorlist/colorlist";
import { Domain } from "@web/core/domain";
import { evaluateBooleanExpr } from "@web/core/py_js/py";
import {
Many2XAutocomplete,
useActiveActions,
useX2ManyCrud,
useOpenMany2XRecord,
} from "@web/views/fields/relational_utils";
import { registry } from "@web/core/registry";
import { Mutex } from "@web/core/utils/concurrency";
import { standardFieldProps } from "../standard_field_props";
import { TagsList } from "@web/core/tags_list/tags_list";
import { usePopover } from "@web/core/popover/popover_hook";
import { useService } from "@web/core/utils/hooks";
import { useTagNavigation } from "@web/core/record_selectors/tag_navigation_hook";
import { Component, useRef } from "@odoo/owl";
import { getFieldDomain } from "@web/model/relational_model/utils";
class Many2ManyTagsFieldColorListPopover extends Component {
static template = "web.Many2ManyTagsFieldColorListPopover";
static components = {
CheckBox,
ColorList,
};
static props = {
colors: Array,
tag: Object,
switchTagColor: Function,
onTagVisibilityChange: Function,
close: Function,
};
}
export class Many2ManyTagsField extends Component {
static template = "web.Many2ManyTagsField";
static components = {
TagsList,
Many2XAutocomplete,
};
static props = {
...standardFieldProps,
canCreate: { type: Boolean, optional: true },
canQuickCreate: { type: Boolean, optional: true },
canCreateEdit: { type: Boolean, optional: true },
colorField: { type: String, optional: true },
createDomain: { type: [Array, Boolean], optional: true },
domain: { type: [Array, Function], optional: true },
context: { type: Object, optional: true },
placeholder: { type: String, optional: true },
nameCreateField: { type: String, optional: true },
searchThreshold: { type: Number, optional: true },
string: { type: String, optional: true },
};
static defaultProps = {
canCreate: true,
canQuickCreate: true,
canCreateEdit: true,
nameCreateField: "name",
context: {},
};
static RECORD_COLORS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
static SEARCH_MORE_LIMIT = 320;
setup() {
this.orm = useService("orm");
this.previousColorsMap = {};
this.popover = usePopover(this.constructor.components.Popover);
this.dialog = useService("dialog");
this.dialogClose = [];
useTagNavigation("many2ManyTagsField", {
isEnabled: () => !this.props.readonly,
delete: (index) => this.deleteTagByIndex(index),
});
this.autoCompleteRef = useRef("autoComplete");
this.mutex = new Mutex();
const { saveRecord, removeRecord } = useX2ManyCrud(
() => this.props.record.data[this.props.name],
true
);
this.activeActions = useActiveActions({
fieldType: "many2many",
crudOptions: {
create: this.props.canCreate && this.props.createDomain,
createEdit: this.props.canCreateEdit,
onDelete: removeRecord,
edit: this.props.record.isInEdition,
},
getEvalParams: (props) => ({
evalContext: this.evalContext,
readonly: props.readonly,
}),
});
this.openMany2xRecord = useOpenMany2XRecord({
resModel: this.relation,
activeActions: {
create: false,
write: true,
},
onRecordSaved: (record) => {
const records = this.props.record.data[this.props.name].records;
return records.find((r) => r.resId === record.resId).load();
},
});
this.update = (recordlist) => {
recordlist = recordlist
? recordlist.filter(
(element) => !this.tags.some((record) => record.resId === element.id)
)
: [];
if (!recordlist.length) {
return;
Registry / API
- Registry name
many2many_tags- Category
fields- Module
web- Slug
many2many-tags- Nav group
forms