From 37cc5266f960b988b058a2b0e65d2f1947f87d0c Mon Sep 17 00:00:00 2001 From: niyasraphy Date: Sun, 20 Aug 2023 18:39:56 +0000 Subject: [PATCH] [FIX] web: missing required attribute for html field To reproduce ============ * referrals -> configuration -> rewards * try creating a new reward keeping description empty * here description is required html field * traceback on clicking save Problem ======= in case of html field, `this.data[fieldName]` is an object `Markup{''}`, so `!this.data[fieldName]` is always `false` as objects are considered as true value in JS. Solution ======== in case of html, check the length of the Markup object opw-3469539 closes odoo/odoo#134365 X-original-commit: dce8e1a8b6137c035488240f8004b870b73c8d51 Signed-off-by: Aaron Bohy (aab) Signed-off-by: Abdelouahab Laaroussi (abla) Co-authored-by: Niyas Raphy --- .../src/model/relational_model/record.js | 5 ++++ .../tests/views/fields/html_field_tests.js | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/addons/web/static/src/model/relational_model/record.js b/addons/web/static/src/model/relational_model/record.js index c9b76a69c8a..795d3f2ebde 100644 --- a/addons/web/static/src/model/relational_model/record.js +++ b/addons/web/static/src/model/relational_model/record.js @@ -335,6 +335,11 @@ export class Record extends DataPoint { case "integer": case "monetary": continue; + case "html": + if (this._isRequired(fieldName) && this.data[fieldName].length === 0) { + unsetRequiredFields.push(fieldName); + } + break; case "one2many": case "many2many": { const list = this.data[fieldName]; diff --git a/addons/web/static/tests/views/fields/html_field_tests.js b/addons/web/static/tests/views/fields/html_field_tests.js index ef273e0c95c..336d4e41192 100644 --- a/addons/web/static/tests/views/fields/html_field_tests.js +++ b/addons/web/static/tests/views/fields/html_field_tests.js @@ -57,6 +57,32 @@ QUnit.module("Fields", ({ beforeEach }) => { assert.strictEqual(target.querySelector(".o_field_html").textContent, "some text"); }); + QUnit.test("html field with required attribute", async function (assert) { + await makeView({ + type: "form", + resModel: "partner", + resId: 1, + serverData, + arch: /* xml */ `
`, + }); + + const textarea = target.querySelector(".o_field_html textarea"); + assert.ok(textarea, "should have a text area"); + + await editInput(textarea, null, ""); + assert.strictEqual(textarea.value, ""); + + await clickSave(target); + assert.strictEqual( + target.querySelector(".o_notification_title").textContent, + "Invalid fields: " + ); + assert.strictEqual( + target.querySelector(".o_notification_content").innerHTML, + "
  • txt
" + ); + }); + QUnit.test("html fields are correctly rendered (edit)", async (assert) => { await makeView({ type: "form",