diff --git a/addons/web/static/src/model/relational_model/record.js b/addons/web/static/src/model/relational_model/record.js index 978b674008c..9ed2c67129c 100644 --- a/addons/web/static/src/model/relational_model/record.js +++ b/addons/web/static/src/model/relational_model/record.js @@ -402,6 +402,15 @@ export class Record extends DataPoint { } break; } + case "json": { + if ( + this._isRequired(fieldName) && + (!this.data[fieldName] || !Object.keys(this.data[fieldName]).length) + ) { + unsetRequiredFields.push(fieldName); + } + break; + } default: if (!this.data[fieldName] && this._isRequired(fieldName)) { unsetRequiredFields.push(fieldName); diff --git a/addons/web/static/tests/helpers/mock_server.js b/addons/web/static/tests/helpers/mock_server.js index 145ace05f26..e22fe96064e 100644 --- a/addons/web/static/tests/helpers/mock_server.js +++ b/addons/web/static/tests/helpers/mock_server.js @@ -55,6 +55,7 @@ const DEFAULT_FIELD_VALUES = { selection: false, reference: false, properties: [], + json: false, }; // ----------------------------------------------------------------------------- diff --git a/addons/web/static/tests/views/form/form_view_tests.js b/addons/web/static/tests/views/form/form_view_tests.js index 5fae239f2a1..92a645e8046 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -55,6 +55,7 @@ import { Field } from "@web/views/fields/field"; import { IntegerField } from "@web/views/fields/integer/integer_field"; import { useSpecialData } from "@web/views/fields/relational_utils"; import { X2ManyField, x2ManyField } from "@web/views/fields/x2many/x2many_field"; +import { standardFieldProps } from "@web/views/fields/standard_field_props"; import { FormController } from "@web/views/form/form_controller"; import { companyService } from "@web/webclient/company_service"; @@ -14541,4 +14542,38 @@ QUnit.module("Views", (hooks) => { ".modal:not(.o_inactive_modal) .modal-footer button[name='someothername']" ); }); + + QUnit.test("an empty json object does not pass the required check", async function (assert) { + assert.expect(3); + serverData.models.partner.fields.json_field = { type: "json" }; + class JsonField extends Component { + onChange(ev) { + this.props.record.update({ [this.props.name]: JSON.parse(ev.target.value) }); + } + } + JsonField.props = standardFieldProps; + JsonField.supportedTypes = ["json"]; + JsonField.template = xml``; + + fieldRegistry.add("json", { component: JsonField }); + const form = await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: `
`, + }); + + patchWithCleanup(form.env.services.notification, { + add: (message, params) => { + assert.strictEqual(message.toString(), "