diff options
| author | Vincent Schippefilt <vsc@odoo.com> | 2018-08-30 16:25:42 +0200 |
|---|---|---|
| committer | Vincent Schippefilt <vsc@odoo.com> | 2018-09-25 16:49:23 +0200 |
| commit | 48a53f2ea5c5cd225a08b65c90b94e0032c0a776 (patch) | |
| tree | a44025d5b4350a83a5cb826adcc7e5effe7ac7b3 /addons/web/static/tests/fields/relational_fields_tests.js | |
| parent | e343f5f5f95607b91a61fed167a6f11f0eeaeaa8 (diff) | |
[FIX] web: improve automatic creation of new lines in x2many in forms
This commit fixes a few issues with the previous implementation of the
automatic addition of new lines in x2many inside forms
1. Before this commit, when there is a change of mode in a formview
`edit` -> `readonly` -> `edit`, there may be some cases that
mistakenly and automatically opens a modal.
This case occurs in a form view with a x2many field whose 1st inner
focusable element opens a modal (e.g. "Add an item").
In `edit` mode:
1. Open this modal from the x2many
2. Close the modal
3. Change mode to `readonly`
4. Change mode to `edit`
> the same modal is automatically open.
This is due to the tracking of the last activated field that persists
after a change of mode. Since the last activated field in the 1st
`edit` is the x2many, it is granted the focus at the beginning of the
2nd `edit`, which automatically opens the modal.
This commit fixes the issue by resetting the tracking of the last
activated field when there is a change of mode. As a result, at the
beginning of the 2nd `edit`, the focus should always be on the 1st
field.
2. Before this commit, if the focus was moved out of the form (to a modal
for instance) then back, the form would re-activate the last field, which
is the x2many and would re-add a new line. This behavior is not correct
and now going back from a modal to a form does not add a new line.
Co-authored-by: Alexandre Kühn <aku@odoo.com>
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 63ac20a0a32..6af69df2f87 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -13404,8 +13404,7 @@ QUnit.module('relational_fields', { }); 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) { + QUnit.test('when Navigating to a many2one with tabs, it receives the focus and adds a new line', function (assert) { assert.expect(3); var form = createView({ @@ -13441,9 +13440,9 @@ QUnit.module('relational_fields', { which: $.ui.keyCode.TAB, keyCode: $.ui.keyCode.TAB, })); - assert.strictEqual(assert.strictEqual(form.$el.find('.o_field_x2many_list_row_add>a')[0], + assert.strictEqual(assert.strictEqual(form.$el.find('input[name="turtle_foo"]')[0], document.activeElement, - "after tab, the focus should be on the many2one on the add new line")); + "after tab, the focus should be on the many2one on the first input of the newly added line")); form.destroy(); }); @@ -13551,7 +13550,7 @@ QUnit.module('relational_fields', { }); QUnit.test('when Navigating to a many to one with tabs, editing in a popup, the popup should receive the focus then give it back', function (assert) { - assert.expect(4); + assert.expect(3); this.data.partner.records[0].turtles = []; @@ -13596,18 +13595,9 @@ QUnit.module('relational_fields', { keyCode: $.ui.keyCode.TAB, })); - assert.strictEqual(form.$el.find('.o_field_x2many_list_row_add a')[0], - document.activeElement, - "after tab, the focus should be on the add new line link"); - - form.$el.find('.o_field_x2many_list_row_add a').trigger($.Event('keydown', { - which: $.ui.keyCode.ENTER, - keyCode: $.ui.keyCode.ENTER, - })); - assert.strictEqual($.find('input[name="turtle_foo"]')[0], document.activeElement, - "after enter, the focus should be in the popup, in the first input field"); + "when the one2many received the focus, the popup should open because it automatically adds a new line"); $('input[name="turtle_foo"]').trigger($.Event('keydown', { which: $.ui.keyCode.ESCAPE, @@ -13618,7 +13608,7 @@ QUnit.module('relational_fields', { document.activeElement, "after escape, the focus should be back on the add new line link"); - form.destroy(); + form.destroy(); }); QUnit.test('navigating through an editable list with custom controls [REQUIRE FOCUS]', function (assert) { |
