pm-controls
Version:
ProModel Controls
60 lines (55 loc) • 1.89 kB
text/typescript
import {
Component,
Input,
OnInit,
Output,
EventEmitter,
ViewChild
} from '@angular/core';
import { TextBoxComponent } from '../text-box/text-box-component';
import { KeyCodes } from '../../../../objects/key-codes';
export class MultiSelectTextBoxComponent {
IsDisabled: boolean;
Watermark: string;
Text: string;
SelectedItems: Array<any> = [];
SelectedItemsChange: EventEmitter<any> = new EventEmitter<any>();
ShowRemoveItem: boolean = true;
textBox: TextBoxComponent;
MultiSelectTextBoxClass: string = "text-box-input";
MultiSelectTextBoxButtonClass: string = "button-icon-default";
MultiSelectTextBoxSelectedItemsClass: string = "multi-select-text-box-selected-items";
Width:any;
MultiSelectTextBoxPanelClass:any;
AddClick() {
if (this.Text)
{
this.SelectedItems.push(this.Text);
this.Text = undefined;
}
}
RemoveSelectedItem(item:any) {
var idx = this.SelectedItems.indexOf(item);
if(idx<0) {
console.error("Could not find selected item to remove.");
console.trace();
return;
}
this.SelectedItems.splice(idx,1);
this.SelectedItemsChange.emit(this.SelectedItems);
this.textBox.Focus();
}
OnKeyUp(event) {
if (event.keyCode == KeyCodes.ENTER) {
if (this.Text) {
this.SelectedItems.push(this.Text);
this.Text = undefined;
}
}
}
}