summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2019-01-31 15:38:52 +0000
committerGéry Debongnie <ged@odoo.com>2019-02-04 08:22:34 +0000
commit1f5807f1c8a263cf3d5dd8c2dc02dc8219f486d2 (patch)
treef62f043946ba52d27a7e0dc12917bd3abf8cd600
parentdc4e2b92aabe9f80de0ffba79901530b6a3e149e (diff)
[FIX] web: allow user to move cursor in search bar
With the control panel refactoring, the auto_complete widget was set on a different target, which caused issues with the search bar: the event handlers for the search bar were triggered before the handlers for the auto_complete widget. With this commit, we make sure they are handled in the proper order. Also, a small piece of code that was supposed to check the position of the cursor was lost. closes odoo/odoo#30795
-rw-r--r--addons/mail/static/tests/discuss_tests.js4
-rw-r--r--addons/web/static/src/js/views/control_panel/search/search_bar.js1
-rw-r--r--addons/web/static/src/js/widgets/auto_complete.js12
3 files changed, 14 insertions, 3 deletions
diff --git a/addons/mail/static/tests/discuss_tests.js b/addons/mail/static/tests/discuss_tests.js
index 5f903898255..2479f417f92 100644
--- a/addons/mail/static/tests/discuss_tests.js
+++ b/addons/mail/static/tests/discuss_tests.js
@@ -179,7 +179,7 @@ QUnit.test('searchview filter messages', function (assert) {
// interact with searchview so that there is only once message
$('.o_searchview_input').val("ab").trigger('keyup');
- $('.o_searchview_input_container').trigger($.Event('keydown', { which: $.ui.keyCode.ENTER }));
+ $('.o_searchview_input').trigger($.Event('keydown', { which: $.ui.keyCode.ENTER }));
assert.strictEqual($('.o_searchview_facet').length, 1,
"the searchview should have a facet");
@@ -191,7 +191,7 @@ QUnit.test('searchview filter messages', function (assert) {
// interact with search view so that there are no matching messages
testUtils.dom.click($('.o_facet_remove'));
$('.o_searchview_input').val("abcd").trigger('keyup');
- $('.o_searchview_input_container').trigger($.Event('keydown', { which: $.ui.keyCode.ENTER }));
+ $('.o_searchview_input').trigger($.Event('keydown', { which: $.ui.keyCode.ENTER }));
assert.strictEqual($('.o_searchview_facet').length, 1,
"the searchview should have a facet");
diff --git a/addons/web/static/src/js/views/control_panel/search/search_bar.js b/addons/web/static/src/js/views/control_panel/search/search_bar.js
index 7f0feda4516..77d6d7fa5e9 100644
--- a/addons/web/static/src/js/views/control_panel/search/search_bar.js
+++ b/addons/web/static/src/js/views/control_panel/search/search_bar.js
@@ -142,6 +142,7 @@ var SearchBar = Widget.extend({
var self = this;
this._setupAutoCompletionWidgets();
this.autoComplete = new AutoComplete(this, {
+ $input: this.$('input'),
source: this._getAutoCompleteSources.bind(this),
select: this._onAutoCompleteSelected.bind(this),
get_search_string: function () {
diff --git a/addons/web/static/src/js/widgets/auto_complete.js b/addons/web/static/src/js/widgets/auto_complete.js
index 33405aa4196..6dd78f8f730 100644
--- a/addons/web/static/src/js/widgets/auto_complete.js
+++ b/addons/web/static/src/js/widgets/auto_complete.js
@@ -19,7 +19,7 @@ return Widget.extend({
// to obtain the current search string.
init: function (parent, options) {
this._super(parent);
- this.$input = parent.$el;
+ this.$input = options.$input;
this.source = options.source;
this.select = options.select;
this.get_search_string = options.get_search_string;
@@ -90,14 +90,24 @@ return Widget.extend({
ev.preventDefault();
break;
case $.ui.keyCode.RIGHT:
+ if(self.$input[0].selectionStart < self.search_string.length) {
+ ev.stopPropagation();
+ return;
+ }
self.searching = false;
var current = self.current_result;
if (current && current.expand && !current.expanded) {
self.expand();
self.searching = true;
+ ev.stopPropagation();
}
ev.preventDefault();
break;
+ case $.ui.keyCode.LEFT:
+ if(self.$input[0].selectionStart > 0) {
+ ev.stopPropagation();
+ }
+ break;
case $.ui.keyCode.ESCAPE:
self.close();
self.searching = false;