From 4b4ea80787c74755aa48ca56539e5de3d30abd54 Mon Sep 17 00:00:00 2001 From: Stanislas Gueniffey Date: Mon, 20 Mar 2023 18:43:32 +0000 Subject: [PATCH] [IMP] web_editor: improve focus() for LinkDialog Previously, LinkDialog always focused on the first editable input field. This commit introduces a new option in the LinkDialog constructor, `focusField`, that allows to designate a specific field to focus on. This option is now used to focus on the second editable input field when the first one is already filled (for example, from the user selection). task-3224551 closes odoo/odoo#119699 X-original-commit: 70649465c35736ae5a8b918817bfd0f598600852 Signed-off-by: David Monjoie (dmo) --- addons/web_editor/static/src/js/wysiwyg/dialog.js | 5 ++++- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/dialog.js b/addons/web_editor/static/src/js/wysiwyg/dialog.js index e1321f478a2..b75e14bdf6d 100644 --- a/addons/web_editor/static/src/js/wysiwyg/dialog.js +++ b/addons/web_editor/static/src/js/wysiwyg/dialog.js @@ -36,7 +36,10 @@ var WysiwygDialog = Dialog.extend({ var self = this; this.opened(function () { - self.$('input:visible:first').focus(); + const selector = options.focusField + ? `input[name=${options.focusField}]` + : 'input:visible:first'; + self.$(selector).focus(); self.$el.closest('.modal').addClass('o_web_editor_dialog'); self.$el.closest('.modal').on('hidden.bs.modal', self.options.onClose); }); diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 03fb1a21bbb..856625f6458 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1265,6 +1265,7 @@ const Wysiwyg = Widget.extend({ const linkDialog = new weWidgets.LinkDialog(this, { forceNewWindow: this.options.linkForceNewWindow, wysiwyg: this, + focusField: link.innerHTML ? 'url' : '', }, this.$editable[0], { needLabel: true }, undefined, link);