Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Add option 'limit' to limit the number of items that can be selected #348

Closed
wants to merge 1 commit into from

Conversation

fdevibe
Copy link

@fdevibe fdevibe commented Oct 27, 2014

In multiple mode, use this option to limit the number of items that can be selected at the same time.

Quite possibly a fairly naïve approach. The tests also aren't optimal, but I haven't found a better way to test them without touching more code. At least it is a suggestion. :-)

This addresses #178.

@YidingW
Copy link

YidingW commented Nov 17, 2014

+1

@amoshche
Copy link

At the moment the workaround is extending the directive, it also work with mouse clicks

    .directive('uiSelect', function (){
      return {
        restrict: 'EA',
        require: 'uiSelect',
        link: function($scope, $element, $attributes, ctrl) {
            $scope.$select.limit = (angular.isDefined($attributes.limit)) ? parseInt($attributes.limit, 10) : undefined;
            var superSelect = ctrl.select;
            ctrl.select = function() {
                if(ctrl.multiple && ctrl.limit !== undefined && ctrl.selected.length >= ctrl.limit) {
                    console.log("booooo");
                } else {
                    superSelect.apply(ctrl, arguments);
                }
            };
        }
      }
    })

@yaneq
Copy link

yaneq commented Nov 26, 2014

Thanks for this @amoshche

@maxisam
Copy link

maxisam commented Jan 27, 2015

+1 Thanks for this @amoshche

@davidstump
Copy link

👍 Thanks @amoshche!

@evillemez
Copy link

👍 Yeah, thanks @amoshche!

@KennyKaplanHP
Copy link

Rather than doing another directive I adjusted the ctrl.activate function by adding in an if block around the remainder of the function. Using the attribute set logic from @fdevibe to add the limit to $select you can use the following to prevent the dropdown list from showing up:

if (ctrl.limit === undefined || ctrl.selected.length < ctrl.limit)

@dimirc dimirc added this to the 0.11.x milestone Feb 21, 2015
@icfantv
Copy link

icfantv commented Apr 3, 2015

I don't see this added yet to the current code base - probably due to the merge conflict above. Is there any intent of adding this feature to the released version? Thanks.

@voznik
Copy link

voznik commented Apr 15, 2015

@amoshche +1 Thanks

@user378230
Copy link
Contributor

Superseded by #1110 (merged)

@user378230 user378230 closed this Mar 23, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.