diff options
| author | Julien Mougenot <jum@odoo.com> | 2019-09-09 11:05:46 +0000 |
|---|---|---|
| committer | Julien Mougenot <jum@odoo.com> | 2019-09-18 08:24:02 +0000 |
| commit | 01d7077bddbf12d430378fa85542f9c04fd11acc (patch) | |
| tree | 6e58da100ecc6b8dcd11118dd55da48618cc8cae /addons/web | |
| parent | 8c6de8c452804094da17ac9e77c6f2b7b047dc29 (diff) | |
[FIX] web: readonly many2one in list views
Fixes the way many2one fields are rendered in editable list views.
Before this commit, many2ones in readonly mode would render as links
and their widget would be considered as active even though you couldn't
edit it.
Now, they are rendered as plain text and act the same way as readonly char fields.
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 19 | ||||
| -rw-r--r-- | addons/web/static/src/xml/base.xml | 4 | ||||
| -rw-r--r-- | addons/web/static/tests/views/list_tests.js | 24 |
3 files changed, 45 insertions, 2 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 8155f9d56f1..5efaa2c8468 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -766,6 +766,25 @@ var FieldMany2One = AbstractField.extend({ }); var ListFieldMany2One = FieldMany2One.extend({ + events: _.extend({}, FieldMany2One.prototype.events, { + 'focusin input': '_onInputFocusin', + }), + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * If in readonly, will never be considered as an active widget. + * + * @override + */ + activate: function () { + if (this.mode === 'readonly') { + return false; + } + return this._super.apply(this, arguments); + }, //-------------------------------------------------------------------------- // Private diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 062571646b6..c8bd34c4cf3 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -829,8 +829,8 @@ <t t-name="FieldMany2One"> <t t-if="widget.mode === 'readonly'"> - <a t-if="!widget.nodeOptions.no_open" t-att-tabindex="widget.attrs.tabindex" class="o_form_uri" href="#"/> - <span t-if="widget.nodeOptions.no_open"/> + <a t-if="!widget.noOpen" t-att-tabindex="widget.attrs.tabindex" class="o_form_uri" href="#"/> + <span t-if="widget.noOpen"/> </t> <div t-if="widget.mode === 'edit'" class="o_field_widget o_field_many2one" aria-atomic="true"> <div class="o_input_dropdown"> diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 1e7f633dc05..7a66cfd8583 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -4703,6 +4703,30 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('editable list view: many2one with readonly modifier', async function (assert) { + assert.expect(2); + + const list = await createView({ + arch: + `<tree editable="top"> + <field name="m2o" readonly="1"/> + <field name="foo"/> + </tree>`, + data: this.data, + model: 'foo', + View: ListView, + }); + + // edit a field + await testUtils.dom.click(list.$('.o_data_row:eq(0) .o_data_cell:eq(0)')); + + assert.containsOnce(list, '.o_data_row:eq(0) .o_data_cell:eq(0) a[name="m2o"]'); + assert.strictEqual(document.activeElement, list.$('.o_data_row:eq(0) .o_data_cell:eq(1) input')[0], + "focus should go to the char input"); + + list.destroy(); + }); + QUnit.test('list grouped by date:month', async function (assert) { assert.expect(1); |
