[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) <dmo@odoo.com>
This commit is contained in:
Stanislas Gueniffey
2023-04-26 17:06:25 +02:00
parent e9528d8741
commit 4b4ea80787
2 changed files with 5 additions and 1 deletions
@@ -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);
});
@@ -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);