diff --git a/addons/web/static/src/views/fields/ace/ace_field.js b/addons/web/static/src/views/fields/ace/ace_field.js index 731cea07a12..4508536db29 100644 --- a/addons/web/static/src/views/fields/ace/ace_field.js +++ b/addons/web/static/src/views/fields/ace/ace_field.js @@ -46,8 +46,12 @@ export class AceField extends Component { } handleChange(editedValue) { - this.props.record.model.bus.trigger("FIELD_IS_DIRTY", true); - this.isDirty = true; + if (this.state.initialValue !== editedValue) { + this.isDirty = true; + } else { + this.isDirty = false; + } + this.props.record.model.bus.trigger("FIELD_IS_DIRTY", this.isDirty); this.editedValue = editedValue; } diff --git a/addons/web/static/tests/views/fields/ace_editor_field_tests.js b/addons/web/static/tests/views/fields/ace_editor_field_tests.js index 5b1575cf0d7..fae5ac0007b 100644 --- a/addons/web/static/tests/views/fields/ace_editor_field_tests.js +++ b/addons/web/static/tests/views/fields/ace_editor_field_tests.js @@ -1,4 +1,5 @@ /** @odoo-module **/ +/* global ace */ import { registry } from "@web/core/registry"; import { @@ -68,6 +69,43 @@ QUnit.module("Fields", (hooks) => { assert.ok(target.querySelector(".o_field_code").textContent.includes("yop")); }); + QUnit.test("AceEditorField mark as dirty as soon at onchange", async function (assert) { + await makeView({ + type: "form", + resModel: "partner", + resId: 1, + serverData, + arch: ` +
+ + `, + }); + + assert.ok("ace" in window, "the ace library should be loaded"); + assert.containsOnce( + target, + "div.ace_content", + "should have rendered something with ace editor" + ); + + assert.ok(target.querySelector(".o_field_code").textContent.includes("yop")); + // edit the foo field + const aceEditor = target.querySelector(".ace_editor"); + ace.edit(aceEditor).setValue("blip"); + await nextTick(); + assert.containsOnce(target, ".o_form_status_indicator_buttons"); + assert.doesNotHaveClass( + target.querySelector(".o_form_status_indicator_buttons"), + "invisible" + ); + + // revert edition + ace.edit(aceEditor).setValue("yop"); + await nextTick(); + assert.containsOnce(target, ".o_form_status_indicator_buttons"); + assert.hasClass(target.querySelector(".o_form_status_indicator_buttons"), "invisible"); + }); + QUnit.test("AceEditorField on html fields works", async function (assert) { serverData.models.partner.fields.htmlField = { string: "HTML Field",