From cf7f110c5e19e3543c3e1896f239295d881a786f Mon Sep 17 00:00:00 2001 From: linusbrolin Date: Mon, 30 May 2016 15:29:55 +0200 Subject: [PATCH] feat(input): Added selectable inputfields instead of forcing id and text. (#213) --- components/select/select.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/select/select.ts b/components/select/select.ts index c50f0f3c..2f47916c 100644 --- a/components/select/select.ts +++ b/components/select/select.ts @@ -190,13 +190,15 @@ let optionsTemplate = ` export class SelectComponent implements OnInit { @Input() public allowClear:boolean = false; @Input() public placeholder:string = ''; + @Input() public idField:string = 'id'; + @Input() public textField:string = 'text'; @Input() public initData:Array = []; @Input() public multiple:boolean = false; @Input() public set items(value:Array) { this._items = value; - this.itemObjects = this._items.map((item:any) => new SelectItem(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() @@ -309,7 +311,7 @@ export class SelectComponent implements OnInit { this.behavior = (this.firstItemHasChildren) ? new ChildrenBehavior(this) : new GenericBehavior(this); if (this.initData) { - this.active = this.initData.map((data:any) => new SelectItem(data)); + this.active = this.initData.map((data:any) => (typeof data === 'string' ? new SelectItem(data) : new SelectItem({id: data[this.idField], text: data[this.textField]}))); this.data.emit(this.active); } }