From 68614027463502a0aedddf2eecda6cf065286283 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Thu, 4 May 2023 15:13:22 +0000 Subject: [PATCH] [FIX] web_editor: save on more than just input Since commit [1], the state of the editor in the html field is only set to dirty when the user triggers an input event. This means that if the user uses the mouse to change the content of the field (eg, drag and dropping snippets), the editor is not marked as dirty so the save button will not appear and autosave will not work. This commit fixes this by checking the editor's dirty state whenever a history step event is triggered. Since this reverts commit [1], we need to ensure the bug it fixed does not reappear. This is done by ensuring we don't check the saved value against the modified editing value when it's empty (namely, the editor doesn't allow an empty string as a value and replaces it with `


`, which we need to undo in `_isDirty`). task-3263653 task-3288416 opw-3274329 [1]: https://github.com/odoo/odoo/pull/113088/commits/095bbb93d6c3b9b0b099b7ed1a6a15e8ad914e9f closes odoo/odoo#122628 X-original-commit: db0c092973f480f3336a44e5f6868dc5a79f0e3a Signed-off-by: David Monjoie (dmo) Signed-off-by: Antoine Guenet (age) --- addons/web_editor/static/src/js/backend/html_field.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/backend/html_field.js b/addons/web_editor/static/src/js/backend/html_field.js index 884df6c65e1..9b396634681 100644 --- a/addons/web_editor/static/src/js/backend/html_field.js +++ b/addons/web_editor/static/src/js/backend/html_field.js @@ -337,7 +337,7 @@ export class HtmlField extends Component { this.wysiwyg.toolbar.$el.append($codeviewButtonToolbar); $codeviewButtonToolbar.click(this.toggleCodeView.bind(this)); } - this.wysiwyg.odooEditor.editable.addEventListener("input", () => + this.wysiwyg.odooEditor.editable.addEventListener("historyStep", () => this.props.record.model.bus.trigger("FIELD_IS_DIRTY", this._isDirty()) ); @@ -415,7 +415,7 @@ export class HtmlField extends Component { _isDirty() { const strippedPropValue = stripHistoryIds(String(this.props.record.data[this.props.name])); const strippedEditingValue = stripHistoryIds(this.getEditingValue()); - return !this.props.readonly && strippedPropValue !== strippedEditingValue; + return !this.props.readonly && (strippedPropValue || '


') !== strippedEditingValue; } _getCodeViewEl() { return this.state.showCodeView && this.codeViewRef.el;