bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

typeahead start with option

Open mese79 opened this issue 12 years ago • 2 comments

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 avatar Nov 11 '14 08:11 mese79

@mese79 you can do this already without any need to modify the existing directive: http://stackoverflow.com/a/18431624/1418796

pkozlowski-opensource avatar Nov 11 '14 08:11 pkozlowski-opensource

Dear mese79 3 year and your answer help me a lot!! Thanks!!!!

niltonjacintho avatar Feb 15 '17 11:02 niltonjacintho