Dojo ComboBox with JsonRest store and loading indicator.

I was using a JsonRest store to populate a dijit ComboBox and FilteringSelect with auto complete and needed to display a spinner or loading message while the JsonRest store was querying.

I googled around for a built in solution and found a couple people asking but no responses.

I am not sure if this is the best approach but a quick and easy enough solution for me was to intercept the functions that are called when a search begins and ends. These functions exist within dijit/form/_SearchMixin.js that the ComboBox and FilteringSelect inherit from:

_SearchMixin._startSearch  -> Called when a search starts
_SearchMixin.onComplete -> Called when a search ends.

Therefore I did something similar to the following to display a loading indicator during store queries. The only down side to this approach is a missing edge case where if the JsonRest store has an error, the loading indicator will continue to display.

<!DOCTYPE html>
<html lang="en">
      <link rel="stylesheet" type="text/css" href=""/>
      <script src=""></script>
          ], function (aspect, Memory, domStyle, ComboBox) {

             var someData = [
                 { id:1, name:"One" },
                 { id:2, name:"Two" }

             var combobox = new ComboBox({
                 store: new Memory( {data: someData }),
                 searchAttr: 'name',
                 autocomplete: true
                 }, 'exampleCombobox');

              function showSpinner() {
                  domStyle.set("exampleSpinner", "display", "block");

              function hideSpinner() {
                  domStyle.set("exampleSpinner", "display", "none");

              aspect.after(combobox, '_startSearch', showSpinner);
              aspect.after(combobox, 'onSearch', hideSpinner);
    <body class="claro">
      <input id="exampleCombobox"/>
      <img src=""


Popular posts from this blog

The SQL Server and .Net equivalent of PHP and MySQL's SHA1 function

Easy .NET MVC Active Directory Attribute Based Authorization

AutoItX4Java - Java AutoIt Bridge