bootstrap
bootstrap copied to clipboard
typeahead start with option
Hi guys! First of all thank you for these great components. I just made some changes in typeahead component to meet my needs to return values only when they start with given input value. but i'm sure this is not the best practice to do it:
var startWith = attrs.hasOwnProperty('typeaheadStartWith') ? true : false;
...
var getMatchesAsync = function(inputValue) {
...
//transform labels
var tempMatches = [];
for(var i=0; i<matches.length; i++) {
locals[parserResult.itemName] = matches[i];
tempMatches.push({
id: getMatchId(i),
label: parserResult.viewMapper(scope, locals),
model: matches[i]
});
}
if (startWith) {
for (var i = 0; i < tempMatches.length; i++) {
if (tempMatches[i].label.toString().indexOf(inputValue.toString()) === 0) {
scope.matches.push(tempMatches[i]);
}
};
} else {
scope.matches = tempMatches;
}
@mese79 you can do this already without any need to modify the existing directive: http://stackoverflow.com/a/18431624/1418796
Dear mese79 3 year and your answer help me a lot!! Thanks!!!!