angular2-multiselect-dropdown
Advanced tools
Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "angular2-multiselect-dropdown", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"license": "MIT", | ||
@@ -19,3 +19,4 @@ "angular-cli": {}, | ||
"devDependencies": { | ||
} | ||
} |
@@ -112,2 +112,3 @@ # Angular2 Multiselect Dropdown | ||
| classes | String | Custom classes to the dropdown component. Classes are added to the dropdown selector tag. To add multiple classes, the value should be space separated class names.| '' | | ||
| limitSelection | Number | Limit the selection of number of items from the dropdown list. Once the limit is reached, all unselected items gets disabled. | none | | ||
@@ -114,0 +115,0 @@ ### Callback Methods |
@@ -73,18 +73,29 @@ import { Component, OnInit, NgModule, OnChanges, ViewEncapsulation,forwardRef, Input, Output, EventEmitter, ElementRef, AfterViewInit, Pipe, PipeTransform } from '@angular/core'; | ||
onItemClick(item: ListItem,index){ | ||
let found = this.isSelected(item); | ||
let found = this.isSelected(item); | ||
let limit = this.selectedItems.length < this.settings.limitSelection ? true : false; | ||
if(!found){ | ||
this.addSelected(item); | ||
this.onSelect.emit(item); | ||
} | ||
else{ | ||
this.removeSelected(item); | ||
this.onDeSelect.emit(item); | ||
} | ||
if(this.isSelectAll || this.data.length > this.selectedItems.length){ | ||
this.isSelectAll = false; | ||
} | ||
if(this.data.length == this.selectedItems.length){ | ||
this.isSelectAll = true; | ||
} | ||
if(!found){ | ||
if(this.settings.limitSelection){ | ||
if(limit){ | ||
this.addSelected(item); | ||
this.onSelect.emit(item); | ||
} | ||
} | ||
else{ | ||
this.addSelected(item); | ||
this.onSelect.emit(item); | ||
} | ||
} | ||
else{ | ||
this.removeSelected(item); | ||
this.onDeSelect.emit(item); | ||
} | ||
if(this.isSelectAll || this.data.length > this.selectedItems.length){ | ||
this.isSelectAll = false; | ||
} | ||
if(this.data.length == this.selectedItems.length){ | ||
this.isSelectAll = true; | ||
} | ||
} | ||
@@ -111,4 +122,10 @@ private onTouchedCallback: () => void = noop; | ||
} | ||
else | ||
this.selectedItems = value; | ||
else{ | ||
if(this.settings.limitSelection){ | ||
this.selectedItems = value.splice(0,this.settings.limitSelection); | ||
} | ||
else{ | ||
this.selectedItems = value; | ||
} | ||
} | ||
} else { | ||
@@ -115,0 +132,0 @@ this.selectedItems = []; |
@@ -11,2 +11,3 @@ export interface DropdownSettings{ | ||
classes: String; | ||
limitSelection?: Number; | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23646
11
268
134