Search Box with Suggestions Dropdown – uniBox.js

The “uniBox.js” is a stand alone and powerful JavaScript plugin to create search box with suggestions dropdown. It helps you to make an AJAX ready search box that can also fetch suggestions from external URLs. The plugin comes with multiple configuration options to fully customize its core working. It is also compatible with jQuery to easily implement in your projects.

Moreover, the looking of search box can be fully customize with additional CSS according to your website template.

Plugin Overview

Plugin: uniBox
Author: David Urbansky
Licence: MIT Licence
Published: October 6, 2019
Repository: Fork on GitHub
Dependencies: No Dependency!
File Type: zip archive (HTML, CSS & JavaScript )
Package Size: 56.7 KB

How to Create Search Box with Suggestions Dropdown

1. First of all load jQuery and uniBox plugin’s CSS and JavaScript files into your HTML document in order to make suggestions search.

<!-- jQuery -->
<script src=""></script>

<!-- UniBox JS -->
<script src="js/unibox.min.js"></script>

<!-- UniBox CSS -->
<link rel="stylesheet" href="css/unibox.min.css"/>

2. After that, create a basic HTML form for search box with unique id.

   <input class="s searchbox" id="searchInput" type="text" placeholder="My search..." />
   <input class="btn-search" type="submit" value="search" />

3. Initialize the plugin with suggestions configurations by adding the following script in your webpage.

     <!-- unibox configuration -->
            var boxes = [];

            sxQuery(document).ready(function() {

                var settings = {
                    // REQUIRED
                    suggestUrl: '', // the URL that provides the data for the suggest -> this is just an example
                    // suggestUrl: '', // the URL that provides the data for the suggest
                    ivfImagePath: '', // the base path for instant visual feedback images

                    // OPTIONAL
                    instantVisualFeedback: 'all', // where the instant visual feedback should be shown, 'top', 'bottom', 'all', or 'none', default: 'all'
                    throttleTime: 100, // the number of milliseconds before the suggest is triggered after finished input, default: 300ms
                    extraHtml: undefined, // extra HTML code that is shown in each search suggest
                    highlight: true, // whether matched words should be highlighted, default: true
                    queryVisualizationHeadline: '', // A headline for the image visualization, default: empty
                    animationSpeed: 200, // speed of the animations, default: 300ms
                    callbacks: {
                        enter: function(text,link){console.log('enter callback: '+text);}, // callback on what should happen when enter is pressed, default: undefined, meaning the link will be followed
                        enterResult: function(text,link){console.log('enter callback result: ' + text);}, // callback on what should happen when enter is pressed on a result or a suggest is clicked
                    placeholder: 'Search for something',
                    minChars: 3, // minimum number of characters before the suggests shows, default: 3
                    suggestOrder: [], // the order of the suggests
                    suggestSelectionOrder: [], // the order of how they should be selected
                    noSuggests: '<b>We haven\'t found anything for you, <u>sooorrryyy</u></b>',
                    emptyQuerySuggests: {
                                        "Cool Things to Check Out":[
                                            {"id":"1","name":"Mason Jar Lid Lights","link":"","image":""},
                                            {"id":"2","name":"Spreadable Beer","link":"","image":""}
                                            {"name":"Canon PowerShot SX710 HS","image":"","id":"2179584","link":""},
                    //maxWidth: 400 // the maximum width of the suggest box, default: as wide as the input box

                // apply the settings to an input that should get the unibox
                // apply to multiple boxes
                boxes = sxQuery(".s").unibox(settings);

In the above JavaScript code, each config option (and its purpose) has been described with comments.

Be the first to comment

Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.