Request on 0.10: Add a class to the first suggestion if autoselect is true
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-autoselectclass to thett-suggestelement that will be autoselected, just like.tt-cursor. - But ensure that
tt-autoselectis only applied when the user has not manually selected anything. In other words, if the user mouses over some other.tt-suggestelement, then.tt-autoselectshould 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.
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.
:+1: Thank you!
+1
It looks like this issue hasn't been assigned to a milestone. Any plans for this in the near-future?
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.
Personally I'd hate to see it removed because my business people love/require autoselect.
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.
There is defiantly a big need for this feature.
Really missing this, if demand is of any importance here's my +1 cents.
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;
},
Can someone post an example on how to implement the getDatumForSuggestion function?
@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.
Ah thanks @galenwilk I thought the function was some callback