Commits

Anonymous committed d15ee74

More fixes

  • Participants
  • Parent commits 730a3c4
  • Branches custom_tooltip

Comments (0)

Files changed (1)

File TestWebsite/Scripts/hAutoComplete/hAutoComplete.js

         that = this; //self reference variable to be used inside functions
         $.fn.hAutoComplete.prototype.lastfocusedInputbox = null;
         padding = 10; //How much padding to leave between text and border
-        minimumSearchLength = 3;
+        minimumSearchLength = 1;
         toolTipContainer = $('<div id="hAutoCompleteContainerBox" class="ui-widget ui-widget-content ui-corner-all">');
         toolTipContainer.css({
             position: 'absolute',
                         term: searchObject.term,
                         controlId: that.attr('id')
                     };
-                    $.extend(dataPackage, searchObject.extraParameters);
+                    $.extend(dataPackage, options.extraParameters);
                     return dataPackage;
                 },
                 success: function(json) {
             var msg, options;
 
             options = {
-                term: '',
-                extraParameters: {}
+                term: ''
             };
 
             $.extend(options, inputOptions);
             if (options.term.length <= 0) {
                 msg = "term needs to be defined for options in hAutocomplete.val() function";
-                throw msg; alert(msg);
+                alert(msg); throw msg;
             }
+
             getFilterResultsFromServer(options, function(result) {
-                if (result.length > 0) {
-                    that.data("uiItem", options.term);
-                    that.val(options.term);
+                if (result.length === 1) {
+                    that.data("uiItem", result[0].id);
+                    that.val(result[0].id);
+                } else {
+                    that.val(that.data("uiItem"));
                 }
             }, false);
         };
                 return;
             }
             if (targetElement.attr('id').toLowerCase() === showAllButtonId.toLowerCase()) {
+                that.data('showAllClicked', true);
                 return;
             }
             toolTipContainer.remove();
+            //that.hAutoComplete.val({ term: that.val() });
         };
 
 
                 var element = $(this);
                 element.data("uiItem", ui.item.id);
                 element.val(ui.item.id);
-                setTimeout(function() { element.val(element.data("uiItem")); }, 10);
+                element.val(element.data("uiItem"));
+                toolTipContainer.remove();
+                return false;
             },
             close: function(event, ui) {
                 //var element = $(this);
             minLength: minimumSearchLength
         };
 
+        if (this.data('initalized')) {
+            this.autocomplete("destroy");
+        }
+        
         this.autocomplete(defaults);
+        this.data('initalized', true);
+
         this.unbind("blur.BlurInputTextBox");
         this.bind("blur.BlurInputTextBox", function(event) {
             var theInputBox = $(this);
-            theInputBox.val(theInputBox.data("uiItem"));
+
+            setTimeout(function() {
+                if (!that.data('showAllClicked')) {
+                    if (theInputBox.val().length <= 0) {
+                        theInputBox.val(theInputBox.data("uiItem"));
+                    }
+                    theInputBox.hAutoComplete.val({ term: theInputBox.val() });
+                } else {
+                    that.data('showAllClicked', false);
+                }
+            }, 20);
         });
         this.data("uiItem", that.val());