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

重启刷新即可

相关推荐
chao1898444 小时前
基于 SPEA2 的多目标优化算法 MATLAB 实现
开发语言·算法·matlab
赏金术士4 小时前
Kotlin 习题集 · 高级篇
android·开发语言·kotlin
子兮曰5 小时前
Bun v1.3.14 深度解析:Image API、HTTP/3、全局虚拟存储与五十项变革
前端·后端·bun
楼兰公子5 小时前
buildroot 在编译rust时裁剪平台类型数量的方法
开发语言·后端·rust
吴声子夜歌5 小时前
Go——并发编程
开发语言·后端·golang
kyriewen6 小时前
今天,百年巨头一次砍了9200人,而一个离职科学家的实话让全网睡不着觉
前端·openai·ai编程
ooseabiscuit6 小时前
Laravel4.x:现代PHP框架的奠基之作
java·开发语言·php
问心无愧05136 小时前
ctf show web 入门42
android·前端·android studio
c1s2d3n4cs6 小时前
Qt模仿nlohmann::json进行序列化和反序列化
开发语言·qt·json
kyriewen6 小时前
老板逼我上AI,我偷偷在浏览器里跑LLaMA,省下20万API费
前端·react.js·llm