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

重启刷新即可

相关推荐
kyriewen1 小时前
别再 console.log 了:5 个 Chrome DevTools 调试技巧,用过就回不去了
前端·javascript·面试
IT_陈寒3 小时前
Python搞不定字符串编码?这破玩意坑我两小时!
前端·人工智能·后端
To_OC3 小时前
LC 1 两数之和:面试第一道必考题,暴力解法直接被面试官 pass
javascript·算法·leetcode
DigitalOcean4 小时前
Laravel 开发者已在 DigitalOcean 上开通超过 10 万台服务器
前端·laravel
星始流年4 小时前
从 Tool 到 Skill——基于 LangChain 的服务端Skill实现
前端·langchain·agent
李惟4 小时前
开源本地通信库,纯客户端 RPC,像聊天一样通信
前端
YAwu114 小时前
深入解析 React 炫彩鼠标跟随标题组件:从坐标定位到动画性能
前端·react.js
GuWenyue4 小时前
排序效率低?5分钟吃透快速排序,性能飙升至O(nlogn)
前端·javascript·面试
OpenTiny社区4 小时前
🎨 看完 GenUI SDK 源码我悟了!
前端·vue.js·github
叁两5 小时前
前端转型AI Agent该如何学习?(前置篇)
前端·人工智能·node.js