diff --git a/addons/web_editor/controllers/main.py b/addons/web_editor/controllers/main.py index f6b5fdd57f5..e5cc1c481fe 100644 --- a/addons/web_editor/controllers/main.py +++ b/addons/web_editor/controllers/main.py @@ -118,7 +118,7 @@ class Web_Editor(http.Controller): htmlelem = etree.fromstring("
%s
" % value, etree.HTMLParser()) checked = bool(checked) - li = htmlelem.find(".//li[@id='%s']" % checklistId) + li = htmlelem.find(".//li[@id='checkId-%s']" % checklistId) if li is None: return value @@ -147,7 +147,7 @@ class Web_Editor(http.Controller): value = getattr(record, filename, False) htmlelem = etree.fromstring("
%s
" % value, etree.HTMLParser()) - stars_widget = htmlelem.find(".//span[@id='%s']" % starsId) + stars_widget = htmlelem.find(".//span[@id='checkId-%s']" % starsId) if stars_widget is None: return value diff --git a/addons/web_editor/static/lib/odoo-editor/src/utils/sanitize.js b/addons/web_editor/static/lib/odoo-editor/src/utils/sanitize.js index 2064cad73f0..f4b5db5e9b1 100644 --- a/addons/web_editor/static/lib/odoo-editor/src/utils/sanitize.js +++ b/addons/web_editor/static/lib/odoo-editor/src/utils/sanitize.js @@ -77,7 +77,16 @@ export function areSimilarElements(node, node2) { class Sanitize { constructor(root) { this.root = root; + // Remove unique ids from checklists and stars. These will be renewed + // afterwards. + for (const node of closestBlock(root).querySelectorAll('[id^=checkId-]')) { + node.removeAttribute('id'); + } this.parse(root); + // Ensure unique ids on checklists and stars. + for (const node of closestBlock(root).querySelectorAll('.o_checklist > li, .o_stars')) { + node.setAttribute('id', `checkId-${Math.floor(new Date() * Math.random())}`); + } } parse(node) { @@ -133,12 +142,6 @@ class Sanitize { } } - // Ensure unique ids on checklists and stars. - if (node.nodeName == 'LI' && node.parentElement && node.parentElement.classList.contains('o_checklist') || - node.classList && node.classList.contains('o_stars')) { - node.setAttribute('id', Math.floor(new Date() * Math.random())); - } - // FIXME not parse out of editable zone... this._parse(node.firstChild); this._parse(node.nextSibling); diff --git a/addons/web_editor/static/lib/odoo-editor/test/spec/list.test.js b/addons/web_editor/static/lib/odoo-editor/test/spec/list.test.js index 8c9e1fb024c..1f20676b972 100644 --- a/addons/web_editor/static/lib/odoo-editor/test/spec/list.test.js +++ b/addons/web_editor/static/lib/odoo-editor/test/spec/list.test.js @@ -237,6 +237,7 @@ describe('List', () => { describe('Insert', () => { it('should turn an empty paragraph into a checklist', async () => { await testEditor(BasicEditor, { + removeCheckIds: true, contentBefore: '

[]

', stepFunction: toggleCheckList, // JW cAfter: '', @@ -245,6 +246,7 @@ describe('List', () => { }); it('should turn a paragraph into a checklist', async () => { await testEditor(BasicEditor, { + removeCheckIds: true, contentBefore: '

ab[]cd

', stepFunction: toggleCheckList, // JW cAfter: '', @@ -253,6 +255,7 @@ describe('List', () => { }); it('should turn a heading into a checklist', async () => { await testEditor(BasicEditor, { + removeCheckIds: true, contentBefore: '

ab[]cd

', stepFunction: toggleCheckList, // JW cAfter: '', @@ -261,6 +264,7 @@ describe('List', () => { }); it('should turn a paragraph in a div into a checklist', async () => { await testEditor(BasicEditor, { + removeCheckIds: true, contentBefore: '

ab[]cd

', stepFunction: toggleCheckList, // JW cAfter: '
', @@ -269,6 +273,7 @@ describe('List', () => { }); it('should turn a paragraph with formats into a checklist', async () => { await testEditor(BasicEditor, { + removeCheckIds: true, contentBefore: '

ab cd ef[]gh

', stepFunction: toggleCheckList, @@ -279,6 +284,7 @@ describe('List', () => { }); it('should turn a paragraph between 2 checklist into a checklist item', async () => { await testEditor(BasicEditor, { + removeCheckIds: true, contentBefore: '

d[]ef

', stepFunction: toggleCheckList, @@ -286,8 +292,9 @@ describe('List', () => { '', }); }); - it('should turn a unordered list into a checklist betweet 2 checklist inside a checklist', async () => { + it('should turn a unordered list into a checklist between 2 checklists inside a checklist', async () => { await testEditor(BasicEditor, { + removeCheckIds: true, contentBefore: unformat(` `), }); await testEditor(BasicEditor, { + removeCheckIds: true, contentBefore: unformat(`