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
diff --git a/erpnext/e_commerce/product_ui/search.js b/erpnext/e_commerce/product_ui/search.js
index 9bae1c1..a2d8566 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 @@
// 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");