diff options
| author | Aaron Bohy <aab@odoo.com> | 2018-09-13 16:09:33 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2018-09-17 13:32:37 +0200 |
| commit | 4393e48fec93d2f0872f48bc4ad172b03c948c24 (patch) | |
| tree | 37de1118bff7c01abb49404dd53376258eee903b /addons/web/static/tests/fields/relational_fields_tests.js | |
| parent | 0354579c986d63b08eb85571602097c49afd1678 (diff) | |
[FIX] web: navigate in editable list with custom controls
Rev. f241441 recently added the possibiliy to define custom
controls (instead of the single 'Add a line') in editable list
views. However, it didn't take into account keyboard navigation.
Suppose that the focus is on the field preceeding the list, and
the user clicks on TAB, the code assumed that there was only one
control, and focused it. However, when there were several control,
the last one was focused (which is typically the less common one),
and there was no way to navigate to the others.
This rev. focuses the first control by default, and allows to
navigate through controls with RIGHT and LEFT. Pressing TAB still
moves out of the list, to the next field.
Note that i'm not happy with this fix, as the logic doesn't seem
to be in the right place. Indeed, the notion of controls is the
concern of the editable list, not the x2many field, so the list
should handle this logic by itself. Unfortenately, this is not that
easy to change, as for now the list doesn't even know that we are
navigating to/from its control(s), until we click on it/them.
Changing that will be for later, in master.
We also did a linting pass on the concerned code.
Task 1878254
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 3a6423f9cdf..2fff96e8ee3 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -4,7 +4,6 @@ odoo.define('web.relational_fields_tests', function (require) { var AbstractField = require('web.AbstractField'); var BasicModel = require('web.BasicModel'); var concurrency = require('web.concurrency'); -var config = require('web.config'); var FormView = require('web.FormView'); var ListRenderer = require('web.ListRenderer'); var ListView = require('web.ListView'); @@ -13354,8 +13353,8 @@ QUnit.module('relational_fields', { form.destroy(); }); - QUnit.module('TabNavigation'); + QUnit.test('when Navigating to a many to one with tabs, it receives the focus on the add new line link', function (assert) { assert.expect(3); @@ -13442,7 +13441,7 @@ QUnit.module('relational_fields', { "after tab, the focus should be on the many2one")); form.destroy(); - }); + }); QUnit.test('when Navigating to a many to one with tabs, not filling in the first field and hitting tab, we should not add a first line but navigate to the next control', function (assert) { assert.expect(3); @@ -13567,6 +13566,73 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('navigating through an editable list with custom controls [REQUIRE FOCUS]', function (assert) { + assert.expect(5); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: + '<form>' + + '<field name="display_name"/>' + + '<field name="p">' + + '<tree editable="bottom">' + + '<control>' + + '<create string="Custom 1" context="{\'default_foo\': \'1\'}"/>' + + '<create string="Custom 2" context="{\'default_foo\': \'2\'}"/>' + + '</control>' + + '<field name="foo"/>' + + '</tree>' + + '</field>' + + '<field name="int_field"/>' + + '</form>', + viewOptions: { + mode: 'edit', + }, + }); + + assert.strictEqual(document.activeElement, form.$('.o_field_widget[name="display_name"]')[0], + "first input should be focused by default"); + + // press tab to navigate to the list + form.$('.o_field_widget[name="display_name"]').trigger($.Event('keydown', { + which: $.ui.keyCode.TAB, + keyCode: $.ui.keyCode.TAB, + })); + + assert.strictEqual(document.activeElement, form.$('.o_field_x2many_list_row_add a:first')[0], + "first editable list control should now have the focus"); + + // press right to focus the second control + form.$('.o_field_x2many_list_row_add a:first').trigger($.Event('keydown', { + which: $.ui.keyCode.RIGHT, + keyCode: $.ui.keyCode.RIGHT, + })); + + assert.strictEqual(document.activeElement, form.$('.o_field_x2many_list_row_add a:nth(1)')[0], + "second editable list control should now have the focus"); + + // press left to come back to first control + form.$('.o_field_x2many_list_row_add a:nth(1)').trigger($.Event('keydown', { + which: $.ui.keyCode.LEFT, + keyCode: $.ui.keyCode.LEFT, + })); + + assert.strictEqual(document.activeElement, form.$('.o_field_x2many_list_row_add a:first')[0], + "first editable list control should now have the focus"); + + // press tab to leave the list + form.$('.o_field_x2many_list_row_add a:first').trigger($.Event('keydown', { + which: $.ui.keyCode.TAB, + keyCode: $.ui.keyCode.TAB, + })); + + assert.strictEqual(document.activeElement, form.$('.o_field_widget[name="int_field"]')[0], + "last input should now be focused"); + + form.destroy(); + }); }); }); }); |
