Skip to content

Commit

Permalink
feat(input): Added selectable inputfields instead of forcing id and t…
Browse files Browse the repository at this point in the history
…ext. (#213)
  • Loading branch information
linusbrolin authored and valorkin committed May 30, 2016
1 parent c178431 commit cf7f110
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = [];
@Input() public multiple:boolean = false;

@Input()
public set items(value:Array<any>) {
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()
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit cf7f110

Please sign in to comment.