angular-strap icon indicating copy to clipboard operation
angular-strap copied to clipboard

No max selected option for multiple select

Open Mattnmoore opened this issue 12 years ago • 4 comments

Is there something I'm missing? It might be extremely useful to include a max-selected option so you can limit how many items a user can select. I'm trying to hack around this to do it, but nothing is really working.

Mattnmoore avatar May 23 '14 21:05 Mattnmoore

I'm running into the same issue. We want to have a multiselect with a high end limit. If this is something we would like to see in the project (angular-strap) proper I can give it shot when I get back next week.

strizzaflex avatar Apr 29 '15 20:04 strizzaflex

I have this working I modified the directive a bit. Changed the watch for model a bit.

Old Directive Watch:

      // Watch model for changes
        scope.$watch(attr.ngModel, function(newValue, oldValue) {
          // console.warn('scope.$watch(%s)', attr.ngModel, newValue, oldValue);
          select.$updateActiveIndex();
          controller.$render();
        }, true);

Modified Directive Watch:

       // Watch model for changes
        scope.$watch(attr.ngModel, function(newValue, oldValue) {
          // console.warn('scope.$watch(%s)', attr.ngModel, newValue, oldValue);
          if(attr.limit < newValue.length){
            for(var i = 0; i < newValue.length; i++){
               if(i >= oldValue.length) break;
               if(!angular.equals(newValue[i], oldValue[i])) break;
            }

            if(i === newValue.length){
              newValue.pop();
            }else{
              newValue.splice(i, 1);
            }
          }

          select.$updateActiveIndex();
          controller.$render();
        }, true);

Can anyone tell me if this is where they expect the change would be made? Should I be doing this in the $select provider instead (not sure I have old and new values there although)?

strizzaflex avatar May 05 '15 16:05 strizzaflex

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 26 '19 07:01 stale[bot]

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar May 05 '19 16:05 lock[bot]