[FIX] web: prevents not dirty forms saving

Purpose
=======
Prevents auto save of not dirty forms with
text fields on page reload and tab/browser closing.

Specifications
==============
The text field default value is making Odoo consider
the form as dirty even when it's not which triggers
auto saving for not dirty forms.

Change the text field widget setDirty condition to
prevent considering empty textarea string dirty.
Typically, if the previous value was false, false and
empty string should be considered as the same value.

Task-3031570

closes odoo/odoo#106619

X-original-commit: 787ef58dd3f91f829509f738ee40c8764c403757
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
amdi-odoo
2022-11-25 19:52:02 +01:00
parent 7214345b25
commit 57c8e7face
2 changed files with 35 additions and 1 deletions
@@ -147,7 +147,7 @@ export function useInputField(params) {
return;
}
if (val !== component.props.value) {
if ((val || false) !== (component.props.value || false)) {
await component.props.update(val);
lastSetValue = inputRef.el.value;
if (component.props.setDirty) {
@@ -11670,6 +11670,40 @@ QUnit.module("Views", (hooks) => {
assert.verifySteps([], "should not save because we do not change anything");
});
QUnit.test("Auto save: save on closing tab/browser (not dirty) with text field", async function (assert) {
serverData.models.partner.fields.bloup = {
string: "Bloup",
type: "text",
default: false,
};
await makeView({
type: "form",
resModel: "partner",
serverData,
arch: `
<form>
<group>
<field name="bloup"/>
</group>
</form>`,
resId: 1,
mockRPC(route, { args, method, model }) {
if (method === "write" && model === "partner") {
assert.step("save"); // should not be called
}
},
});
assert.strictEqual(target.querySelector(".o_field_widget[name=bloup] textarea").value, "", "should contain the default value");
window.dispatchEvent(new Event("beforeunload"));
await nextTick();
assert.verifySteps([], "should not save because we do not change anything");
});
QUnit.test("Auto save: save on closing tab/browser (detached form)", async function (assert) {
serverData.actions[1] = {
id: 1,