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

重启刷新即可

相关推荐
谭光志9 小时前
如何从网站提取设计风格:DOM、计算样式与 DESIGN.md
前端·javascript·agent
深念Y9 小时前
登录日志与管理员审计日志存储决策
前端·arm开发·后端·微服务·云原生·架构
INGNIGHT10 小时前
1908 · 布尔表达式求值(stack单调栈&dfs)
开发语言·c++·算法
笨笨饿10 小时前
#121_图传中的H.364编码与MP4的联系
linux·运维·前端·单片机·嵌入式硬件·面试·职场和发展
এ慕ོ冬℘゜10 小时前
深入理解浏览器全屏 API:从 requestFullscreen 到全屏实战
开发语言·html
柒和远方10 小时前
V079: Milvus 向量数据库:AI 日记本的三组件部署、集合字段建模与余弦索引
javascript·sql
水獭比特10 小时前
Anthropic Files / Skills 迁移:Workspace 不是租户隔离,API Key 也不是用户身份
javascript
默_笙10 小时前
☕ 我给 TS 类型做了台"瘦身手术",还顺手用 Docker 起了个 MySQL
前端·javascript
七夜zippoe11 小时前
DolphinDB 高可用部署实战:从容灾设计到故障自动转移
开发语言·python·高可用·容灾·dolphindb
不会就选b11 小时前
Linux之线程池(三)
linux·开发语言