[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
This commit is contained in:
Lucas Perais
2022-09-01 15:33:07 +02:00
parent 86feda1968
commit e8ef723a89
+10 -1
View File
@@ -13,7 +13,7 @@ const { Component, useEffect, xml } = owl;
const fieldRegistry = registry.category("fields");
const legacyFieldTemplate = xml`
<FieldAdapter Component="FieldWidget" fieldParams="fieldParams" update.bind="update" record="props.record"/>`;
<FieldAdapter Component="FieldWidget" fieldParams="fieldParams" update.bind="update" record="props.record" id="props.id"/>`;
// -----------------------------------------------------------------------------
// 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