Skip to content

Commit

Permalink
fix(select): allow empty items
Browse files Browse the repository at this point in the history
* chore(package): update tslint-config-valorsoft to version 1.0.4

https://greenkeeper.io/

* check invalid data in items and remove them

* fig bug if incoming data is undefined
  • Loading branch information
Aleksey authored and valorkin committed Jun 24, 2016
1 parent f83764f commit 2c090f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,16 @@ export class SelectComponent implements OnInit {

@Input()
public set items(value:Array<any>) {
this._items = value;
this.itemObjects = this._items.map((item:any) => (typeof item === 'string' ? new SelectItem(item) : new SelectItem({id: item[this.idField], text: item[this.textField]})));
if (!value) {
this._items = this.itemObjects = [];
} else {
this._items = value.filter((item:any) => {
if ((typeof item === 'string' && item) || (typeof item === 'object' && item && item.text && item.id)) {
return item;
}
});
this.itemObjects = this._items.map((item:any) => (typeof item === 'string' ? new SelectItem(item) : new SelectItem({id: item[this.idField], text: item[this.textField]})));
}
}

@Input()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"source-map-loader": "0.1.5",
"systemjs-builder": "0.15.19",
"ts-loader": "0.8.2",
"tslint-config-valorsoft": "1.0.3",
"tslint-config-valorsoft": "1.0.4",
"typescript": "1.8.10",
"typings": "0.8.1",
"webpack": "1.13.1",
Expand Down

0 comments on commit 2c090f3

Please sign in to comment.