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

重启刷新即可

相关推荐
一次旅行20 小时前
多智能体编排实战:拆解Plan-and-Execute范式+三层记忆架构,手写无依赖轻量Agent调度引擎
前端·javascript·架构
用户昵称10020 小时前
C/C++编程-工程实践-本地存储log的工程意义
c语言·开发语言
小玮看世界21 小时前
[Python]从“脏”数据到优雅实现:一个IoT滑动窗口最大值问题的测试驱动优化实录
linux·前端·python
吹什么轩21 小时前
c++复习:map和set的使用
开发语言·c++
尤乐娃子1 天前
进入大厂(厂子大)实习Day11
前端·笔记·实习
必须得开心呀1 天前
qt生成dump文件并定位异常
开发语言·qt
fpcc1 天前
跟我学C++中级篇—内存流
开发语言·c++
xiaoxiangsiyan1 天前
运维之前端反调试学习
运维·前端·学习·状态模式
Cicada1281 天前
ccvt:一个用 Rust 写的中国地图坐标系互转命令行工具
开发语言·后端·rust