How to add Search Suggest at a search bar at the Home page

Hi all,

I’ve added a search bar in my home page since my boss wants the search bar to be larger. I’ve added it using this code

{{include reference=“Main.Search” /}}

but when I type a keyworks there is no live suggestion showing up. It is possible to add search suggest and a live suggestion on the search bar I’ve added on the home page? Same function with the search bar at the top right corner?


Adding the quick search form / input to a page is relatively easy:

#set ($output = $xwiki.getDocument('XWiki.QuickSearchUIX').get('content'))
$output.replace('<li>', '').replace('</li>', '').replace('globalsearch-close', '')

plus some CSS tweaking. The issue is with getting search suggestions and the problem is that currently searchSuggest.js is enhancing only one input (the one from the top bar). It needs to be changed in order to make it enhance multiple inputs. Something like:

--- a/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/uicomponents/search/searchSuggest.js
+++ b/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/uicomponents/search/searchSuggest.js
@@ -229,7 +229,9 @@ var XWiki = (function (XWiki) {
     var sources = $jsontool.serialize($sources);
-    new XWiki.SearchSuggest($('headerglobalsearchinput'), sources);
+    $$('#headerglobalsearchinput, .search-suggest').forEach(function(input) {
+      new XWiki.SearchSuggest(input, sources);
+    });
     return true;

I guess the change will be overwritten with the next update if I make a change in the original file.
Is there a way to implement the changes and make them survive the updates?


You can write your own JavaScript code that calls new XWiki.SearchSuggest(input, sources) but the problem is the sources parameter, for which you’d have to copy the code from searchSuggest.js that computes its value.

Best is to report an improvement on Loading... and then to create a PR based on the changes I suggested.