Categories
post

Patch for VisualSearch.js To Prevent AutoSearching

I learned about VisualSearch today when I listened to The Javascript Show podcast.

I started using it for some backend work. However, I did not like the fact that as soon as you completed a facet, it did the search automatically. Don’t get me wrong, it is great for the way DocumentCloud is using it. Very ajax responsive, but for what I am trying to do, I needed that to stop.

I changed it so that I could pass autosearch: false as a parameter to VisualSearch. Now it will only search after hitting enter.

--- visualsearch.js        2011-08-04 13:16:46.000000000 -0400
+++ visualsearch.js     2011-08-04 13:23:21.000000000 -0400
@@ -30,6 +30,7 @@
     var defaults = {
       container   : '',
       query       : '',
+      autosearch  : true,
       unquotable  : [],
       callbacks   : {
         search          : $.noop,
@@ -543,7 +544,9 @@
         var originalValue = this.model.get('value');
         this.set(ui.item.value);
         if (originalValue != ui.item.value || this.box.val() != ui.item.value) {
-          this.search(e);
+            if (this.options.app.options.autosearch) {
+                this.search(e);
+            }
         }
         return false;
       }, this)