javascript - How to set goog.ui.Autocomplete minimum input to 0 -


i autocomplete show entire list when input box gets focused (no input given). auto complete match substrings without having fiddle private variables.

at moment code is:

autocomplete = goog.ui.ac.createsimpleautocomplete(   gsa.game.gamedata.teams, team2, false); matcher=autocomplete.getmatcher(); matcher.usesimilar_=true autocomplete.setmatcher(matcher); 

similar matches work have set private variable (no getter or setter available).

the other 1 have not been able find out; how show data when no input given (like smart select input). when textbox receives focus it'll show data since there no filter text given. these basic things 1 configure can't find in api documentation.

you need create descendants of goog.ui.ac.autocomplete, goog.ui.ac.arraymatcher , goog.ui.ac.inputhandler. directly create instance of auto complete object instead of calling goog.ui.ac.createsimpleautocomplete.


in goog.ui.ac.autocomplete descendant assign custom input handler , matcher.

goog.provide('my.ui.ac.autocomplete');  goog.require('goog.ui.ac.renderer'); goog.require('my.ui.ac.arraymatcher'); goog.require('my.ui.ac.inputhandler');   my.ui.ac.autocomplete = function(data, input, opt_multi, opt_usesimilar) {      var renderer = new goog.ui.ac.renderer();     var matcher = new my.ui.ac.arraymatcher(data, !opt_usesimilar);     var inputhandler = new my.ui.ac.inputhandler(null, null, !!opt_multi, 300);      goog.ui.ac.autocomplete.call(this, matcher, renderer, inputhandler);     inputhandler.attachautocomplete(this);     inputhandler.attachinputs(input); }; goog.inherits(my.ui.ac.autocomplete, goog.ui.ac.autocomplete); 

in goog.ui.ac.arraymatcher descendant need override getprefixmatches() method, since default behaviour discards empty strings. if there empty string, return first x rows data.

goog.provide('my.ui.ac.arraymatcher');  goog.require('goog.ui.ac.arraymatcher');   my.ui.ac.arraymatcher = function(rows, opt_nosimilar) {     goog.ui.ac.arraymatcher.call(this, rows, opt_nosimilar); }; goog.inherits(my.ui.ac.arraymatcher, goog.ui.ac.arraymatcher);   my.ui.ac.arraymatcher.prototype.getprefixmatches = function(token, maxmatches) {             if (token == '')     {         // empty search string, return first maxmatches rows         return this.rows_.slice(0, maxmatches);     }     else     {         return goog.base(this, 'getprefixmatches', token, maxmatches);     } }; 

in goog.ui.ac.inputhandler descendant need override processfocus() method, , force show autocomplete popup. can done calling update() method first parameter set true.

goog.provide('my.ui.ac.inputhandler');  goog.require('goog.ui.ac.inputhandler');   my.ui.ac.inputhandler = function(opt_separators, opt_literals, opt_multi, opt_throttletime) {     goog.ui.ac.inputhandler.call(this, opt_separators, opt_literals, opt_multi, opt_throttletime); }; goog.inherits(my.ui.ac.inputhandler, goog.ui.ac.inputhandler);   my.ui.ac.inputhandler.prototype.processfocus = function(target) {     goog.base(this, 'processfocus', target);      // force autocomplete popup show     this.update(true); }; 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -