From f63f250630788c56ce4f32a86975e7df2c8c42bc Mon Sep 17 00:00:00 2001 From: marination Date: Mon, 29 Nov 2021 13:45:33 +0530 Subject: [PATCH] feat: Allow addition of custom search box - allow passing custom search box class to bind search actions on - this allows users to inject and get a custom search box running on any page --- erpnext/e_commerce/product_ui/search.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/erpnext/e_commerce/product_ui/search.js b/erpnext/e_commerce/product_ui/search.js index 9bae1c10bc..a2d8566e75 100644 --- a/erpnext/e_commerce/product_ui/search.js +++ b/erpnext/e_commerce/product_ui/search.js @@ -1,7 +1,10 @@ erpnext.ProductSearch = class { - constructor() { + constructor(opts) { + /* Options: search_box_class (for custom search box) */ + $.extend(this, opts); this.MAX_RECENT_SEARCHES = 4; - this.searchBox = $("#search-box"); + this.search_box_class = this.search_box_class || "#search-box" + this.searchBox = $(this.search_box_class); this.setupSearchDropDown(); this.bindSearchAction(); @@ -24,7 +27,7 @@ erpnext.ProductSearch = class { // If click occurs outside search input/results, hide results. // Click can happen anywhere on the page $("body").on("click", (e) => { - let searchEvent = $(e.target).closest('#search-box').length; + let searchEvent = $(e.target).closest(this.search_box_class).length; let resultsEvent = $(e.target).closest('#search-results-container').length; let isResultHidden = this.search_dropdown.hasClass("hidden");