diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-11-02 13:44:53 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-11-02 13:44:53 +0100 |
| commit | 9a32dacd8c30860b24ea191f16f7d0ade6d9c3b2 (patch) | |
| tree | 6fe30958ff15bbd759563d06f0b6a1813d95247a /addons/web/static | |
| parent | dafc3fb7928b3e1325d61060f7402fb148675347 (diff) | |
| parent | ee2b9fae3519c2494f34dacf15d0a3b5bd8fbd06 (diff) | |
[MERGE] forward port branch 11.0 up to ee2b9fae351
Diffstat (limited to 'addons/web/static')
4 files changed, 69 insertions, 7 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index f2cacb3327f..ae3080b3b8e 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -534,14 +534,17 @@ var FieldMany2One = AbstractField.extend({ * start/end of the input element. Stops any navigation move event if the * user is selecting text. * - * TODO this is a duplicate of InputField._onNavigationMove, maybe this - * should be done in a mixin or, better, the m2o field should be an - * InputField (but this requires some refactoring). - * * @private * @param {OdooEvent} ev */ - _onNavigationMove: basicFields.InputField.prototype._onNavigationMove, + _onNavigationMove: function (ev) { + // TODO Maybe this should be done in a mixin or, better, the m2o field + // should be an InputField (but this requires some refactoring). + basicFields.InputField.prototype._onNavigationMove.apply(this, arguments); + if (this.mode === 'edit' && $(this.$input.autocomplete('widget')).is(':visible')) { + ev.stopPropagation(); + } + }, /** * @private * @param {OdooEvent} event diff --git a/addons/web/static/src/js/widgets/model_field_selector.js b/addons/web/static/src/js/widgets/model_field_selector.js index a8daa781119..b82c2ed1963 100644 --- a/addons/web/static/src/js/widgets/model_field_selector.js +++ b/addons/web/static/src/js/widgets/model_field_selector.js @@ -257,7 +257,7 @@ var ModelFieldSelector = Widget.extend({ if (this.dirty) { this.dirty = false; - this.pages = this.pages.slice(0, this.chain.length); + this.pages = this.pages.slice(0, this.chain.length || 1); this.trigger_up("field_chain_changed", {chain: this.chain}); } }, diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index f21db07f088..fe98eaaeab2 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -572,6 +572,38 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('many2one field and list navigation', function (assert) { + assert.expect(3); + + var list = createView({ + View: ListView, + model: 'partner', + data: this.data, + arch: '<tree editable="bottom"><field name="trululu"/></tree>', + }); + + // edit first input, to trigger autocomplete + list.$('.o_data_row .o_data_cell').first().click(); + list.$('.o_data_cell input').val('').trigger('input'); + + // press keydown, to select first choice + list.$('.o_data_cell input').focus().trigger($.Event('keydown', { + which: $.ui.keyCode.DOWN, + keyCode: $.ui.keyCode.DOWN, + })); + + // we now check that the dropdown is open (and that the focus did not go + // to the next line) + var $dropdown = list.$('.o_field_many2one input').autocomplete('widget'); + assert.ok($dropdown.is(':visible'), "dropdown should be visible"); + assert.ok(list.$('.o_data_row:eq(0)').hasClass('o_selected_row'), + 'first data row should still be selected'); + assert.ok(!list.$('.o_data_row:eq(1)').hasClass('o_selected_row'), + 'second data row should not be selected'); + + list.destroy(); + }); + QUnit.test('standalone many2one field', function (assert) { assert.expect(3); var done = assert.async(); diff --git a/addons/web/static/tests/widgets/model_field_selector_tests.js b/addons/web/static/tests/widgets/model_field_selector_tests.js index d92e41760dc..d331f898d42 100644 --- a/addons/web/static/tests/widgets/model_field_selector_tests.js +++ b/addons/web/static/tests/widgets/model_field_selector_tests.js @@ -50,7 +50,7 @@ QUnit.module('ModelFieldSelector', { }, function () { QUnit.test("creating a field chain from scratch", function (assert) { - assert.expect(10); + assert.expect(13); var $target = $("#qunit-fixture"); @@ -124,6 +124,33 @@ QUnit.module('ModelFieldSelector', { "field selector popover should be closed now"); assert.strictEqual(getValueFromDOM($value), "Product -> Product Name", "field selector value should be displayed with two tags: 'Product' and 'Product Name'"); + + // Remove the current selection and recreate it again + fieldSelector.$el.trigger('focusin'); + fieldSelector.$('.o_field_selector_prev_page').click(); + fieldSelector.$('.o_field_selector_close').click(); + + fieldSelector.$el.trigger('focusin'); + $fieldSelectorPopover = fieldSelector.$(".o_field_selector_popover:visible"); + $lis = $fieldSelectorPopover.find("li"); + $productLi = $(); + $lis.each(function () { + var $li = $(this); + if ($li.html().indexOf("Product") >= 0) { + $productLi = $li; + } + }); + assert.strictEqual($productLi.length, 1, + "field selector popover should contain the 'Product' field"); + + $productLi.click(); + $lis = $fieldSelectorPopover.find("li"); + $lis.first().click(); + assert.notOk($fieldSelectorPopover.is("visible"), + "field selector popover should be closed now"); + assert.strictEqual(getValueFromDOM($value), "Product -> Product Name", + "field selector value should be displayed with two tags: 'Product' and 'Product Name'"); + fieldSelector.destroy(); function getValueFromDOM($dom) { |
