[FIX] web: correctly handle (no result) selection in search
In the recent control panel refactoring, selecting '(no result)' (when using the autocomplete on a many2one for example) was no correctly handled and was leading to a traceback. It is now correctly handled and the search bar is correctly re-rendered. Task 1936745 closes odoo/odoo#31438
This commit is contained in:
@@ -17,6 +17,7 @@ var ControlPanelController = mvc.Controller.extend({
|
||||
activate_time_range: '_onActivateTimeRange',
|
||||
autocompletion_filter: '_onAutoCompletionFilter',
|
||||
reload: '_onReload',
|
||||
reset: '_onReset',
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -238,6 +239,15 @@ var ControlPanelController = mvc.Controller.extend({
|
||||
ev.stopPropagation();
|
||||
this.trigger_up('search', this.model.getQuery());
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @param {OdooEvent} ev
|
||||
*/
|
||||
_onReset: function (ev) {
|
||||
ev.stopPropagation();
|
||||
var state = this.model.get();
|
||||
this.renderer.updateState(state);
|
||||
},
|
||||
});
|
||||
|
||||
return ControlPanelController;
|
||||
|
||||
@@ -184,10 +184,16 @@ var SearchBar = Widget.extend({
|
||||
*/
|
||||
_onAutoCompleteSelected: function (e, ui) {
|
||||
e.preventDefault();
|
||||
var filter = ui.item.facet.filter;
|
||||
var facet = ui.item.facet;
|
||||
if (!facet) {
|
||||
// this happens when selecting "(no result)" item
|
||||
this.trigger_up('reset');
|
||||
return;
|
||||
}
|
||||
var filter = facet.filter;
|
||||
if (filter.type === 'field') {
|
||||
var values = filter.autoCompleteValues;
|
||||
values.push(ui.item.facet.values[0]);
|
||||
values.push(facet.values[0]);
|
||||
this.trigger_up('autocompletion_filter', {
|
||||
filterId: filter.id,
|
||||
autoCompleteValues: values,
|
||||
|
||||
@@ -201,10 +201,8 @@ return Widget.extend({
|
||||
this.current_result = $li.data('result');
|
||||
},
|
||||
select_item: function (ev) {
|
||||
if (this.current_result.facet) {
|
||||
this.select(ev, {item: {facet: this.current_result.facet}});
|
||||
this.close();
|
||||
}
|
||||
this.select(ev, {item: {facet: this.current_result.facet}});
|
||||
this.close();
|
||||
},
|
||||
show: function () {
|
||||
this.$el.show();
|
||||
|
||||
@@ -1006,7 +1006,6 @@ QUnit.module('Search View', {
|
||||
actions: this.actions,
|
||||
archs: this.archs,
|
||||
data: this.data,
|
||||
debug: 1,
|
||||
mockRPC: function (route, args) {
|
||||
if (route === '/web/dataset/search_read') {
|
||||
if (searchRead === 1) {
|
||||
@@ -1083,6 +1082,35 @@ QUnit.module('Search View', {
|
||||
actionManager.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('selecting (no result) triggers a re-render', function (assert) {
|
||||
assert.expect(3);
|
||||
var actionManager = createActionManager({
|
||||
actions: this.actions,
|
||||
archs: this.archs,
|
||||
data: this.data,
|
||||
});
|
||||
|
||||
actionManager.doAction(10);
|
||||
|
||||
// 'a' key to filter nothing on bar
|
||||
actionManager.$('.o_searchview_input').val('a');
|
||||
actionManager.$('.o_searchview_input').trigger($.Event('keypress', { which: 65, keyCode: 65 }));
|
||||
actionManager.$('.o_searchview_input').trigger($.Event('keydown', { which: $.ui.keyCode.DOWN, keyCode: $.ui.keyCode.DOWN }));
|
||||
actionManager.$('.o_searchview_input').trigger($.Event('keydown', { which: $.ui.keyCode.RIGHT, keyCode: $.ui.keyCode.RIGHT }));
|
||||
actionManager.$('.o_searchview_input').trigger($.Event('keydown', { which: $.ui.keyCode.DOWN, keyCode: $.ui.keyCode.DOWN }));
|
||||
|
||||
assert.strictEqual(actionManager.$('.o_searchview_autocomplete .o-selection-focus').text(), "(no result)",
|
||||
"there should be no result for 'a' in bar");
|
||||
|
||||
actionManager.$('.o_searchview_input').trigger($.Event('keydown', { which: $.ui.keyCode.ENTER, keyCode: $.ui.keyCode.ENTER }));
|
||||
|
||||
assert.containsNone(actionManager, '.o_searchview_facet_label');
|
||||
assert.strictEqual(actionManager.$('.o_searchview_input').val(), "",
|
||||
"the search input should be re-rendered");
|
||||
|
||||
actionManager.destroy();
|
||||
});
|
||||
|
||||
QUnit.module('TimeRangeMenu');
|
||||
|
||||
QUnit.test('time range menu stays hidden', function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user