From e8ef723a89c68cfc6dbde231f2d888f8de9d84aa Mon Sep 17 00:00:00 2001 From: Lucas Perais Date: Wed, 31 Aug 2022 09:11:43 +0000 Subject: [PATCH] [FIX] web: legacyFields: put fieldId on the focusable element Before this commit, the dom ID of a field was not put onto the legacy fields' focusable dom node. It prevented a form view containing legacy field to properly focus the default_field. After this commit, a legacy field's focusable element can be focused at the init of the FormView Part-of: odoo/odoo#99297 --- addons/web/static/src/legacy/legacy_fields.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/legacy/legacy_fields.js b/addons/web/static/src/legacy/legacy_fields.js index ba4bcb3b29d..e8ed4f2c42f 100644 --- a/addons/web/static/src/legacy/legacy_fields.js +++ b/addons/web/static/src/legacy/legacy_fields.js @@ -13,7 +13,7 @@ const { Component, useEffect, xml } = owl; const fieldRegistry = registry.category("fields"); const legacyFieldTemplate = xml` - `; + `; // ----------------------------------------------------------------------------- // FieldAdapter @@ -30,6 +30,15 @@ class FieldAdapter extends ComponentAdapter { if (!this.widgetEl || !this.widgetEl.parentElement) { return; } + + const fieldId = this.props.id; + if (!this.widgetEl.querySelector(`#${fieldId}`)) { + const $el = this.widget.getFocusableElement(); + if ($el && $el[0]) { + $el[0].setAttribute("id", fieldId); + } + } + // if classNames are given to the field, we only want // to add those classes to the legacy field without // the parent element affecting the style of the field