odoo18 关闭搜索框点击自动弹出下拉框
话不多说,直接贴代码
/** @odoo-module **/
import { patch } from "@web/core/utils/patch";
import { SearchBar } from "@web/search/search_bar/search_bar";
import { useEffect } from "@odoo/owl";
patch(SearchBar.prototype, {
setup() {
super.setup(...arguments);
useEffect(
() => {
let inputEl = null;
if (this.inputRef && this.inputRef.el) {
inputEl = this.inputRef.el;
} else if (this.rootRef && this.rootRef.el) {
inputEl = this.rootRef.el.querySelector('.o_searchview_input');
}
if (inputEl) {
const blockDropdown = (ev) => {
ev.stopPropagation();
ev.stopImmediatePropagation();
};
inputEl.addEventListener("focus", blockDropdown, { capture: true });
inputEl.addEventListener("focusin", blockDropdown, { capture: true });
inputEl.addEventListener("click", blockDropdown, { capture: true });
inputEl.addEventListener("mousedown", blockDropdown, { capture: true });
return () => {
inputEl.removeEventListener("focus", blockDropdown, { capture: true });
inputEl.removeEventListener("focusin", blockDropdown, { capture: true });
inputEl.removeEventListener("click", blockDropdown, { capture: true });
inputEl.removeEventListener("mousedown", blockDropdown, { capture: true });
};
}
},
() => [
this.inputRef ? this.inputRef.el : null,
this.rootRef ? this.rootRef.el : null
]
);
}
});
使用方式, 将文件放到 my_module/static/src/js/disable_searchbar_dropdown.js
在__manifest__.py 导入
py
'assets': {
'web.assets_backend': [
'sz_base/static/src/**/*'
]
},
重启刷新即可