Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added selectable inputfields instead of forcing id and text. #213

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,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 @@ -235,7 +237,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