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

Provide minLength option, akin to Bootstrap's #120

Closed
brianmhunt opened this issue Mar 15, 2013 · 5 comments
Closed

Provide minLength option, akin to Bootstrap's #120

brianmhunt opened this issue Mar 15, 2013 · 5 comments
Milestone

Comments

@brianmhunt
Copy link

Following up on Issue #119, it would be great to have an equivalent minLength option that operated the same way as Bootstrap's, namely “The minimum character length needed before triggering autocomplete suggestions”.

It may be worth noting that when minLength is 0 for Bootstrap typeahead the autocomplete dropdown appears when the <input> tag is focused.

@jharding
Copy link
Contributor

Can you go into a little more detail about what Bootstrap does with minLength is 0? I'm a little confused.

The way I'm thinking of implementing this is if the query is less than minLength characters, datasets will always return an empty array when Dataset#getSuggestions is called. Does that sound reasonable?

@brianmhunt
Copy link
Author

Many thanks Jake.

If minLength is zero in Bootstrap typeahead, then any query will be called and the results will be shown when the input is focused (up to item elements).

It has occurred to me that one may wish to have minLength vary per datum? A use case is as follows:

A prefetch that returns the 8 most recent items with a min length of zero so these results are shown on focusing the input, plus a remote data source that searches prefixes once the minLength is 2 characters, followed by a fulltext search when the length reaches 6 characters. That may be convoluted, but hope the illustration is useful / interesting.

One could achieve this programmatically in Bootstrap with an asynchronous source and minLength of 0.

EDIT Which is all to say, simply returning an empty dataset when the input length is less than the minLength is different from how Bootstrap does it. One could work around this with asynchronous sources, or alternatively a callback or event when the input is less than the minLength and the ability to programatically open the dropdown.

I hope that's helpful food for thought! Congrats on 0.9.0!

Cheers

@jharding
Copy link
Contributor

I could see how it'd be useful to support the minLength option at the dataset level and at the typeahead level. I'll look into implementing that behavior.

@jharding
Copy link
Contributor

So for now, minLength is going to be supported at the dataset level. We want to support something along the lines of default suggestions, but it's still up for debate how we're going to go about that.

@brianmhunt
Copy link
Author

Thanks @jharding .

One thing I just noted, it seems that when the minLength is 0 in Bootstrap Typeahead it no longer (as of 2.3.1) shows the drop-down. Whether this is a change committed since the prior version I was using (2.0.4) or I had monkey-patched BT to show the dropdown, I am unsure offhand.

In any case, I am delighted to see Issue #62 - it really is great for some paradigms.

Arguably, if these were to interact, I believe minLength of zero and an empty query '' ought to show some sort of defaults. Alternatively, one could use a contrived query parameter to show defaults (true, false, undefined, null, {'show': 'defaults'}, etc.).

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

No branches or pull requests

2 participants