diff --git a/addons/web/static/src/js/views/kanban/kanban_record.js b/addons/web/static/src/js/views/kanban/kanban_record.js index 6929ca6f2a2..a217fc51b30 100644 --- a/addons/web/static/src/js/views/kanban/kanban_record.js +++ b/addons/web/static/src/js/views/kanban/kanban_record.js @@ -87,6 +87,22 @@ var KanbanRecord = Widget.extend(WidgetAdapterMixin, { // Public //-------------------------------------------------------------------------- + /** + * Check if a html content is empty. If there are only formatting tags with + * style attributes or a void content. Famous use case is + * '


' added by some web editor(s). + * Note that because the use of this method is limited, we ignore the cases + * like there's one tag in the content. In such case, even if it's the + * actual content, we consider it empty. + * + * @param {string} htmlContent + * @returns {boolean} true if no content found or if containing only formatting tags + */ + isHtmlEmpty: function (htmlContent) { + let div = document.createElement('div'); + div.innerHTML = htmlContent || ""; + return div.innerText.trim() === ""; + }, /** * Re-renders the record with a new state * diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index b548b5838e3..6385a430f16 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -7528,6 +7528,43 @@ QUnit.module('Views', { kanban.destroy(); }); + + QUnit.test('kanban with isHtmlEmpty method', async function (assert) { + assert.expect(3); + + this.data.product.fields.description = {string: 'Description', type: 'html'}; + this.data.product.records.push( + {id: 11, display_name: "product 11", description: "hello"}, + {id: 12, display_name: "product 12", description: "


"}, + ); + + var kanban = await createView({ + View: KanbanView, + model: 'product', + data: this.data, + arch: ` + + +
+ +
+ +
+
+
+
`, + domain: [['id', 'in', [11, 12]]], + + }); + assert.containsOnce(kanban, '.o_kanban_record:first div.test', + "the container is displayed if description have actual content"); + assert.strictEqual(kanban.$('.o_kanban_record:first div.test span.text-info').html().trim(), 'hello', + "the inner html content is rendered properly"); + assert.containsNone(kanban, '.o_kanban_record:last div.test', + "the container is not displayed if description just have formatting tags and no actual content"); + + kanban.destroy(); + }); }); });