odoo18 关闭搜索框点击自动弹出下拉框

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/**/*'
        ]
    },

重启刷新即可

相关推荐
Sarvartha2 小时前
final 关键字
java·开发语言
程序员Sunday2 小时前
JavaScript 事件循环面试题,宏任务与微任务怎么执行|Sunday面试指南
开发语言·javascript·面试·校招·事件循环·程序员sunday
Setsuna_F_Seiei2 小时前
前端转型 Agent 开发 06 之 Agent Memory 记忆系统(让 Agent 更智能,更懂你)
前端·agent·ai编程
zhangzeyuaaa3 小时前
Ruby 多线程、GVL(GIL)与 Mutex 完全指南
开发语言·前端·ruby
默_笙4 小时前
🌊 向量库和 ES 都查不出"关系",我只好给奶茶建了一张人脉网
前端·javascript
优选资讯4 小时前
标签打印软件怎么对接 Excel 数据
前端·excel
谢亮_vipxieliang4 小时前
用 PHP 构建轻量级 REST API:从路由到鉴权的完整实践
开发语言·后端·php
思无邪664 小时前
用 AI 做 JS 逆向:从抓包到复现的完整方法论
开发语言·javascript·人工智能
一个风轻云淡5 小时前
GCC 和 GDB命令简单解读
java·linux·前端
H.莓飛5 小时前
【数据结构】二叉树_OJ题
linux·开发语言·数据结构·算法