bevacqua / horsey

:horse: Progressive and customizable autocomplete component

Home Page:https://bevacqua.github.io/horsey

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Limiting results after X characters entered

sauldraws opened this issue · comments

Struggling with one thing, If I wanted to not show the autocomplete options until a user has entered X number of characters how would I do it, I suspect it has to do with filter but I'm having zero luck

Try this:

var horse = horsey(el, filter: function (q, suggestion) {
  if (q.length < min) {
    return false;
  }
  return horse.defaultFilter(q, suggestion);
});

I guess I'm trying to use it incorrectly

horsey(document.querySelector('#s'), {
    suggestions: ['banana', 'apple', 'orange'],
    filter: function (q, suggestion) { if (q.length < 3) { return false; } return horse.defaultFilter(q, suggestion);}
    }
});

Does that not work for you?

Am I using it correctly? Doesn't seem too

You have an extra } in line 4, that may be your problem

This works

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/horsey/2.6.1/horsey.min.js"></script>    
    <script>
    var horse = horsey(document.querySelector('#s'), {
    suggestions: ['banana', 'apple', 'orange'],
    filter: function (q, suggestion) { if (q.length < 2) { 
        console.log(q);
        return false; 
        } 
    return horse.defaultFilter(q, suggestion);
    }
});
    </script>

Hi @bevacqua ,

It works, but does not prevents the suggestions method to be executed. Ajax inside there will be executed but keep hidden. Any Ideia in how to prevent suggestions? Duplicated the code inside there does not looks good to me. Than you.