Show Jquery UI Autocomplete only when a special key is pressed -


i have textbox autocomplete , want show results when dot key . pressed.

i tried:

 $("#tags").on("keypress", function () {      var keys = [];      keys.unshift(e.which);      if (string.fromcharcode(keys[0]) == ".") {       } else {          $("#tags").unbind();      }  }); 

however, $("#tags").unbind(); removes events textbox, , if press dot key again, results won't show up.

how can fix this? live jsfiddle

here solution emulates visual studio does: http://jsfiddle.net/xhy6n/2/
stores location of last "." , uses after filter autocomplete.

 $(function () {      var availabletags = [          "actionscript", "applescript", "asp", "basic", "c", "c++", "clojure", "cobol", "coldfusion", "erlang", "fortran", "groovy", "haskell", "java", "javascript", "lisp", "perl", "php", "python", "ruby", "scala", "scheme"];      var lastdot = -1;       $("#tags").autocomplete({          minlength: 0,          source: function (request, response) {              if (lastdot>=0) {                  response($.ui.autocomplete.filter(                  availabletags, extractlast(request.term.substring(lastdot+1))));                        }          },          focus: function () {              return false;          },          select: function (event, ui) {              var terms = split(this.value);              terms.pop();              terms.push(ui.item.value);              terms.push("");              this.value = this.value.substr(0,lastdot+1);              this.value += terms.join("");              return false;          }      }).on("keypress", function (e) {          var keys = [];          keys.unshift(e.which);          if (string.fromcharcode(keys[0]) == ".") {              lastdot =  $("#tags").val().length;           }      });       function split(val) {          return val.split(/,\s*/);      }       function extractlast(term) {          return split(term).pop();      }  }); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -