0

I have a drop down where the item size is large so I am looking for a way to enable keyboard-input (key press) so that I can type and it automatically moves to that option in the drop down. Any suggestions?

<ul uib-dropdown-menu role="menu" style="max-height: 150px; overflow-y: auto; max-width : 10px">
  <li ng-repeat="value in feature.values | unknownValueFilter | featureValueOrder ">
    <a ng-click="currentValue.set(value)" href="">
      {{value | featureValueFormatter }}
    </a>
  </li>
</ul>
3

2 Answers 2

1

You may try to use filter on <li> in conjunction with ng-keyup on <ul> for example.

<ul uib-dropdown-menu role="menu" style="max-height: 150px; overflow-y: auto; max-width : 10px" ng-keyup="onKeyUp($event)">
  <li ng-repeat="value in feature.values | filter: tappedKeys | unknownValueFilter | featureValueOrder ">
    <a ng-click="currentValue.set(value)" href="">
      {{value | featureValueFormatter }}
    </a>
  </li>
</ul>

And add in your controller:

$scope.tappedKeys = '';

$scope.onKeyUp = (e)=>{
  $scope.tappedKeys += e.key;
};

But you should think on how to clear typed value.

However in any case I would suggest you to decrease your list someway or create visible filter (text input maybe). Otherwise user will barely understand such behavior.

Sign up to request clarification or add additional context in comments.

6 Comments

@GPost : I tried like you mentioned but not seeing it happens.
@GPost : plnkr.co/edit/9rpuHzlZ1gSMd3fHHxHP?p=preview but still its not working
You have to use ng-repeat on <li> node and use filter on it to see some effect
Figured it out. Thanks :) but once I select when I try to select again the options are resetting back. Can you suggest me a way to clear up ? I am new to angular. Would much appreciate if you let me know what should I use to clear the pressed keys
@user3407267, my suggestion is in looking for another way:) It's better for user to see the filter. Otherwise you may try to use $timeout() in onKeyUp() callback, in which you will set early defined variable to true clearFlag = true. Then each time you're in onKeyUp() check for the flag: if (clearFlag === true) {$scope.tappedKeys = ''}. Figure out others steps by yourself=)
|
0

All you need is to use ng-model and apply it as a filter in ng-repeat. Rest is done automatically by angularjs.

For example:

<ul>
    <li>
        <input type="text" ng-model="searchString" placeholder="Search" />
    </li>
    <li ng-repeat="item in all_items | filter: searchString">
        <a href="" ng-click="blabla(item.key)">{{item.val}}</a>
    </li>
</ul>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.