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

Show dropdown with default suggestions if minLength is 0 #719

Closed
wants to merge 1 commit into from

Conversation

maurizi
Copy link

@maurizi maurizi commented Feb 25, 2014

Mostly captures the changes in #390, but updated for typeahead v0.10

Ditches #390's concept of defaultSort since there is now sorting builtin.

@crockpotveggies
Copy link

+1 - I hope this can be integrated rather quickly since it's definitely makes typeahead more usable and follows other trends in UI.

@AlleSchonWeg
Copy link

It shows the default suggestions, but if you start typing the default suggestions are not filtered.

@meagle
Copy link

meagle commented Mar 5, 2014

+1

@jharding
Copy link
Contributor

jharding commented Mar 7, 2014

From the quick glance I just took, seems like a solid pull request. I'll take a closer look when I get a chance and let you know if I feel anything needs to be changed. Thanks for submitting this.

if (matches.length < this.limit && this.transport) {
cacheHit = this._getFromRemote(query, returnRemoteMatches);
if (query === '') {
matches = this.index.serialize().datums.slice(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add SearchIndex#all so that we don't have to reach into the internals of SearchIndex here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@maurizi
Copy link
Author

maurizi commented Mar 8, 2014

@jharding I have some code in this PR to remove the placeholder attribute on the input when the hint is shown, and add it back when the hint is removed.

I was on the fence about doing this or alternatively not showing a hint when the query is empty. Thoughts?

@maurizi
Copy link
Author

maurizi commented Mar 9, 2014

@Saftpresse99 Do you have an example of this? Maybe you're using different options than what I tested with.

@baslr
Copy link

baslr commented Mar 19, 2014

👍 for this feature :)

@snjypl
Copy link

snjypl commented Mar 20, 2014

+1

@marcusasplund
Copy link

+1 for remote. Also maybe think about making triggering configurable? Only on focus might be useful, but annoying in other cases, but one still might want to hook in to the "show all" with e.g. a click-event from whatever. 0.10.* is an awesome rewrite, btw.

@mokesmokes
Copy link

Would make sense if the prefetched data can be the default suggestions.

@samleb
Copy link

samleb commented Mar 23, 2014

@mokesmokes: agreed, 👍 for this feature in general

@maurizi
Copy link
Author

maurizi commented Mar 23, 2014

@mokesmokes I've been using it with prefetched data for the default suggestions.

@mokesmokes
Copy link

@maurizi Can you please post a usage example? I am porting this project to the Titanium mobile framework, and in the course of that port added an initialData property to the dataset options - probably similar to yours. I also exported readFromStorage from Bloodhound, call that during the Bloodhound initialization done method, and then initialize the typeahead with that initial data in the dataset.

@maurizi
Copy link
Author

maurizi commented Mar 25, 2014

@mokesmokes The only thing you should need to do to get default suggestions to show up is pass 0 as the minLength option to the typeahead, like so:

    $('#input').typeahead({
        minLength: 0
    }, {
        source: engine.ttAdapter(),
        templates: {
            suggestion: template
        },
    });

@theoephraim
Copy link

👍 Looks good!

@yoanisgil
Copy link

@maurizi I'm trying to use this feature in my code, but it looks like I'm doing something wrong. This is my code:

    var objects = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        local: this[collection_name].map(function(obj){
            return {value: obj.get(search_attribute), id: obj.get('id')};
        })
    });

    objects.initialize();

    $(target).find('input').typeahead({
            hint: true,
            highlight: true,
            minLength: 0,
            showDefault: true
        },
        {
            name: 'objects',
            displayKey: 'value',
            source: objects.ttAdapter()
        });

Any idea about what I'm doing wrong?

@maurizi
Copy link
Author

maurizi commented Apr 11, 2014

@yoanisgil I haven't used this with local, maybe I messed something up.

I'll investigate this as soon as I can and see what's going on.

Though I will say that showDefault isn't necessary or used by this PR, the only thing that should be needed is to have a minLength of 0

@njj
Copy link

njj commented Apr 11, 2014

@maurizi fwiw, I was able to get this to work by extracting some bits of your changes into the current version of typeahead. But when building yours my typeahead failed silently.

@yoanisgil
Copy link

I will try to put together a more comprehensive example, but I cannot get this feature to work out of the box. For instance I cloned your typeahead fork and included the bundled file in my project, and that did not work. Seems like I need to build with bower first before I can use it, right?

Le 2014-04-10 à 09:35 PM, Michael Maurizi [email protected] a écrit :

@yoanisgil I haven't used this with local, maybe I messed something up.

I'll investigate this as soon as I can and see what's going on.

Though I will say that showDefault isn't necessary or used by this PR, the only thing that should be needed is to have a minLength of 0


Reply to this email directly or view it on GitHub.

@maurizi
Copy link
Author

maurizi commented Apr 11, 2014

@yoanisgil Did you run grunt to rebuild the bundled files? Per the project standards, I didn't rebuild the files in dist/

@yoanisgil
Copy link

No, I did not … but I’m also knew to grunt. Will do that and see what comes up.

Will keep you posted.
Le 2014-04-10 à 11:37 PM, Michael Maurizi [email protected] a écrit :

@yoanisgil Did you run grunt to rebuild the bundled files? Per the project standards, I didn't rebuild the files in dist/


Reply to this email directly or view it on GitHub.

@njj
Copy link

njj commented Apr 11, 2014

@yoanisgil should be able to run npm install then grunt.

@jharding jharding modified the milestones: Better Events, v0.11.0 Aug 15, 2014
@andrezimpel
Copy link

+1

2 similar comments
@nickmerwin
Copy link

+1

@91bananas
Copy link

+1

@san7hos
Copy link

san7hos commented Oct 6, 2014

Any chance that this is getting released any time soon (say 1 month period)?

@JoryUK
Copy link

JoryUK commented Oct 15, 2014

I have manually made these same changes (from azavea's branch) to 10.5 and it works like a charm.
I'm surprised its taken so long to fix this issue / implement this feature one way or another

@dessita
Copy link

dessita commented Oct 24, 2014

+1

1 similar comment
@roberttdev
Copy link

+1

@dessita
Copy link

dessita commented Nov 4, 2014

Any chance these merge conflict to get resolved anytime soon?

@ksimuk
Copy link

ksimuk commented Nov 12, 2014

👍

@fgravin
Copy link

fgravin commented Nov 13, 2014

Is there a simple hack to implement like it was the case in previous version (on click event)

$('input.tt-query').on('click', function() {           

   ...               

  $.each(ttView.datasets[0].itemHash, function(i, item) {
       fullSuggestionList.push(item);
  });

  ttView.dropdownView.renderSuggestions(
      ttView.datasets[0], fullSuggestionList);
  ttView.inputView.setHintValue('');
  ttView.dropdownView.open();

   ...

@vectart
Copy link

vectart commented Nov 19, 2014

+1

@dhendo
Copy link

dhendo commented Nov 26, 2014

+1 - it would be good to provide an unfiltered list on downKeyed for discoverability purposes

@asaarnak
Copy link

+1

@alemangui
Copy link

Just a small hackish way to accomplish this for those still struggling:

$('.typeahead-input').on( 'focus', function() {
    if($(this).val() === '') // you can also check for minLength
        $(this).data().ttTypeahead.input.trigger('queryChanged', '');
});

@powange
Copy link

powange commented Jan 29, 2015

+1

2 similar comments
@ghost
Copy link

ghost commented Mar 16, 2015

+1

@ageorgousakis
Copy link

+1

@jlbooker
Copy link
Contributor

+1 👍 Would also like to use this to show previous searches when the input element receives focus.

@jharding
Copy link
Contributor

v0.11 just shipped and it adds support for displaying the menu when minLength === 0. Check this example out for more detail.

@jharding jharding closed this Apr 25, 2015
@91bananas
Copy link

#praisejesus


David Cushman | TopOPPS

On Sat, Apr 25, 2015 at 3:32 AM, Jake Harding [email protected]
wrote:

Closed #719.

Reply to this email directly or view it on GitHub:
#719 (comment)

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

Successfully merging this pull request may close these issues.