typeahead.js icon indicating copy to clipboard operation
typeahead.js copied to clipboard

Request on 0.10: Add a class to the first suggestion if autoselect is true

Open chibicode opened this issue 13 years ago • 12 comments

Hi, thank you for this great plugin :) I've tried out the integration-0.10.0 branch and love the new APIs. I have one request on autoselect (related to #332 ): would it be possible to:

  • Add a tt-autoselect class to the tt-suggest element that will be autoselected, just like .tt-cursor.
  • But ensure that tt-autoselect is only applied when the user has not manually selected anything. In other words, if the user mouses over some other .tt-suggest element, then .tt-autoselect should be removed from the first element until the user selects nothing again.

This way, even if hint is false, I'll be able to use CSS to signal users which suggestion will be autoselected upon hitting enter.

Since the first element will always be auto-selected, I thought of using .tt-suggest:first-child in my CSS, but this doesn't work when there are more than one sections.

chibicode avatar Oct 14 '13 00:10 chibicode

Great point. Seeing as how v0.10 is about overdue by 5 or so months (my bad), I'm going to put this in the v0.10.1 milestone.

jharding avatar Dec 27 '13 06:12 jharding

:+1: Thank you!

chibicode avatar Dec 29 '13 01:12 chibicode

+1

It looks like this issue hasn't been assigned to a milestone. Any plans for this in the near-future?

dsposito avatar Jun 03 '14 23:06 dsposito

I'm actually leaning towards removing the autoselect functionality, so to answer @dsposito's question, there are no plans for this in the near-future.

jharding avatar Jul 09 '14 00:07 jharding

Personally I'd hate to see it removed because my business people love/require autoselect.

marshals avatar Jul 09 '14 14:07 marshals

Yeah, I'm torn on what I should do. On one hand, I think the current implementation is half-baked so I don't want to encourage people to use it. On the other hand, it's something a lot people seem to use, so there's clearly a need for the functionality. At the very least, I won't remove the current implementation until there's something to replace it with.

jharding avatar Jul 09 '14 18:07 jharding

There is defiantly a big need for this feature.

simplenotezy avatar Sep 02 '14 13:09 simplenotezy

Really missing this, if demand is of any importance here's my +1 cents.

kobykorman avatar Dec 21 '14 21:12 kobykorman

Change the getDatumForSuggestion function to this one below when using autocomplete to auto-select the first item.

getDatumForSuggestion: function getDatumForSuggestion($el) {
                var datum = null;
                if ($el.length) {
                    if(!this._getCursor().length){
                      this._setCursor(this._getSuggestions().first(),true);
                    }
                    datum = {
                        raw: Dataset.extractDatum($el),
                        value: Dataset.extractValue($el),
                        datasetName: Dataset.extractDatasetName($el)
                    };
                }
                return datum;
            },

WillemStaels avatar Mar 01 '15 12:03 WillemStaels

Can someone post an example on how to implement the getDatumForSuggestion function?

PierBover avatar Jun 02 '15 01:06 PierBover

@PierBover just make sure you've enabled the autoselect: true option when initializing your typeahead. Then in the typeahead.js source replace the existing getDatumForSuggestion function with the one above.

galenwilk avatar Jun 03 '15 17:06 galenwilk

Ah thanks @galenwilk I thought the function was some callback

PierBover avatar Jun 03 '15 17:06 PierBover