Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limiting results after X characters entered #17

Closed
sauldraws opened this issue Jul 24, 2015 · 8 comments
Closed

Limiting results after X characters entered #17

sauldraws opened this issue Jul 24, 2015 · 8 comments
Labels

Comments

@sauldraws
Copy link

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

@bevacqua
Copy link
Owner

Try this:

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

@sauldraws
Copy link
Author

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);}
    }
});

@bevacqua
Copy link
Owner

Does that not work for you?

@sauldraws
Copy link
Author

Am I using it correctly? Doesn't seem too

@bevacqua
Copy link
Owner

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

@sauldraws
Copy link
Author

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>

@bevacqua
Copy link
Owner

Cool!

@wbotelhos
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants