javascript - autocomplete.js exclude words from triggering search -


i'm using http://autocompletejs.com/ , client asking if words can excluded, or say, "treated neutral", , not trigger autocomplete box displaying.

in other words, let's following items in list:

  • tree green
  • tree red
  • tree real
  • tree fake
  • tree tall
  • tree trunk
  • plant green
  • plant bush

they want results display tree/plant first word, typing tree or plant should not trigger list. user have type "tree r" before results appear. or can type "r" see results contain r in second word.

i can't set minlength because want user able enter "re" see red/real results.

another way around ignoring first word of items on list.

any ideas?

it looks can set preprocess option: http://autocompletejs.com/examples#2003

or more correct option matchoptions option: http://autocompletejs.com/examples#4041

in case of latter, idea figure out how many spaces in user's search term , return results same amount of spaces.

note: want trim user's input make sure not errant results. assume using jquery since .trim not have full browser compatibility, feel free implement own trim method in line below comment.

var matchoptions = function(input, matchedoptions, alloptions, value) {     // note: sure trim input first.     var term = $.trim(input)         spacesinsearchterm = term.split(" ").length,         validoptions = [];      (var = 0, l = matchedoptions.length; < l; ++) {         if (matchedoptions[i].split(" ").length === spacesinsearchterm)             validlist.push(list[l]);     }      return validoptions; }; 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -