[FIX] web: handle falsy m2m_tags
Before this change, if a user left a string value in a m2m_tags and removed it afterward without selecting a tag, the update method of Many2XAutoComplete would be called with false. As the update method for m2m_tags expects a record or record list this caused a traceback. The fix is to simply skip the update in that case. task-3109811 closes odoo/odoo#110123 X-original-commit: 14f314feb7594dc888de6af4e4ad23a948044854 Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
@@ -53,6 +53,9 @@ export class Many2ManyTagsField extends Component {
|
||||
});
|
||||
|
||||
this.update = (recordlist) => {
|
||||
if (!recordlist) {
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(recordlist)) {
|
||||
const resIds = recordlist.map((rec) => rec.id);
|
||||
return saveRecord(resIds);
|
||||
|
||||
@@ -959,6 +959,44 @@ QUnit.module("Fields", (hooks) => {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("input and remove text without selecting any tag or option", async function (assert) {
|
||||
serverData.models.partner_type.records.push({ id: 13, display_name: "red", color: 8 });
|
||||
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
arch: '<form><field name="timmy" widget="many2many_tags"/></form>',
|
||||
});
|
||||
|
||||
assert.containsNone(target, ".o_field_many2many_tags .badge");
|
||||
const input = target.querySelector(".o_field_many2many_tags input");
|
||||
|
||||
// enter some text
|
||||
await triggerEvent(input, null, "focus");
|
||||
await click(input);
|
||||
await editInput(input, null, "go");
|
||||
// ensure no selection
|
||||
for (const item of [...target.querySelectorAll(".o-autocomplete--dropdown-menu .o-autocomplete--dropdown-item")]) {
|
||||
triggerEvent(item, null, "mouseleave");
|
||||
}
|
||||
await triggerEvent(input, null, "blur");
|
||||
// ensure we're not adding any value
|
||||
assert.containsNone(document.body, ".modal");
|
||||
assert.containsNone(target, ".o_field_many2many_tags .badge");
|
||||
|
||||
// remove the added text to test behaviour with falsy value
|
||||
await triggerEvent(input, null, "focus");
|
||||
await click(input);
|
||||
await editInput(input, null, "");
|
||||
for (const item of [...target.querySelectorAll(".o-autocomplete--dropdown-menu .o-autocomplete--dropdown-item")]) {
|
||||
triggerEvent(item, null, "mouseleave");
|
||||
}
|
||||
await triggerEvent(input, null, "blur");
|
||||
assert.containsNone(document.body, ".modal");
|
||||
assert.containsNone(target, ".o_field_many2many_tags .badge");
|
||||
});
|
||||
|
||||
QUnit.test("Many2ManyTagsField in one2many with display_name", async function (assert) {
|
||||
serverData.models.turtle.records[0].partner_ids = [2];
|
||||
serverData.views = {
|
||||
|
||||
Reference in New Issue
Block a user