[IMP] web: trim keywords in the search bar

When the search field is used to query an element, the value is
trimmed to remove unnecessary spaces before and after the actual
keywords. This eliminates the annoyance of a search having no
result because of a space that was left (for example when copy-
pasting some text). A test has been added to check if a value
has been trimmed when the text input contains spaces.

closes odoo/odoo#82193

Signed-off-by: Géry Debongnie <ged@odoo.com>
This commit is contained in:
luvi
2022-01-14 07:47:08 +00:00
parent 493908f7d0
commit 741b79cfcc
2 changed files with 36 additions and 1 deletions
+4 -1
View File
@@ -1517,7 +1517,10 @@ export class SearchModel extends EventBus {
const domains = autocompleteValues.map(({ label, value, operator }) => {
let domain;
if (field.filterDomain) {
domain = new Domain(field.filterDomain).toList({ self: label, raw_value: value });
domain = new Domain(field.filterDomain).toList({
self: label.trim(),
raw_value: value,
});
} else {
domain = [[field.fieldName, operator, value]];
}
@@ -659,6 +659,38 @@ QUnit.module("Search", (hooks) => {
assert.deepEqual(getDomain(controlPanel), [["bool", "=", false]]);
});
QUnit.test("the search value is trimmed to remove unnecessary spaces", async function (assert) {
const controlPanel = await makeWithSearch({
serverData,
resModel: "partner",
Component: ControlPanel,
searchMenuTypes: [],
searchViewId: false,
searchViewArch: `
<search>
<field name="foo" filter_domain="[('foo', 'ilike', self)]"/>
</search>
`,
});
await editSearch(controlPanel, "bar");
await validateSearch(controlPanel);
assert.deepEqual(getDomain(controlPanel), [["foo", "ilike", "bar"]]);
await removeFacet(controlPanel);
assert.deepEqual(getDomain(controlPanel), []);
await editSearch(controlPanel, " bar ");
await validateSearch(controlPanel);
assert.deepEqual(
getDomain(controlPanel),
[["foo", "ilike", "bar"]],
"the value has been trimmed"
);
});
QUnit.test("reference fields are supported in search view", async function (assert) {
assert.expect(4);