UNPKG

@ng2select/combo

Version:

<!-- Title: ng2select Description: Angular 2 bootstrap select directive module Author: ng2select -->

124 lines 5.79 kB
"use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var core_1 = require('@angular/core'); var common_1 = require('@angular/common'); var core_2 = require('../../core'); var combo_select_1 = require('../combo-select'); var ComboSelectComponent = (function (_super) { __extends(ComboSelectComponent, _super); function ComboSelectComponent() { _super.call(this); } ComboSelectComponent.prototype.ngOnInit = function () { }; ComboSelectComponent.prototype.ngAfterContentInit = function () { var _this = this; this.options.changes.subscribe(function (options) { return options.forEach(function (option) { if (_this.ngModel) _this.syncNgModelSingleselect(_this.ngModel); option.click.subscribe(function (o) { return _this.setNgModelSingleselect(o); }); }); }); }; ComboSelectComponent.prototype.onBlur = function ($event) { var _this = this; var option = this.options.filter(function (o) { return o.title == _this.inputTitle; })[0]; if (!option) { this.inputTitle = this.title; return; } this.setNgModelSingleselect(option); this.toggle(false); //onsole.log('blur => this.options', this.options); }; ComboSelectComponent.prototype.onChange = function (option) { if (!option || !option.elem) return; console.log('comboInputChanged', option); this.setNgModelSingleselect(option); }; ComboSelectComponent.prototype.onComboInputChange = function ($event) { console.log('$event', $event); }; ComboSelectComponent.prototype.onFocus = function ($event) { var inputElem = $event.target; inputElem.setSelectionRange(0, inputElem.value.length); }; ComboSelectComponent.prototype.onKeydown = function ($event) { console.warn('$event', [$event]); switch ($event.keyCode) { case core_2.KEYCODE.DOWN: this.toggle(true); // let values = this.options.map(); //.filter(o => o.value == this.ngModel); // // // this.setNgModelSingleselect(option); break; default: break; } }; ComboSelectComponent.prototype.onInputKeydown = function ($event) { console.warn('$event', [$event]); switch ($event.keyCode) { case core_2.KEYCODE.ENTER: this.onBlur($event); break; default: break; } }; ComboSelectComponent.prototype.setNgModelSingleselect = function (option) { /* Set all option's active property as false using the observable list */ this.options.forEach(function (option) { return option.active = false; }); /* Set the clicked option's active property to true using the observable list */ this.options.filter(function (o) { return o.value == option.value; }).forEach(function (o) { return o.active = true; }); this.onNgModelChanged(option.value); this.change.emit(option.value); this.setTitle(option); }; ComboSelectComponent.prototype.setTitle = function (option) { if (!option || !option.elem) return; this.title = option.title; }; ComboSelectComponent.prototype.syncNgModelSingleselect = function (newVal) { this.options.forEach(function (o) { return o.active = false; }); var activeOptions = this.options.filter(function (o) { return o.value === newVal; }); activeOptions.forEach(function (o) { return o.active = true; }); this.setTitle(activeOptions[0]); }; /* Override writeValue() from ControlValueAccessor */ ComboSelectComponent.prototype.writeValue = function (newVal) { _super.prototype.writeValue.call(this, newVal); if (this.options) this.syncNgModelSingleselect(newVal); }; ComboSelectComponent = __decorate([ core_1.Component({ moduleId: module.id, selector: 'ix-combo-select', templateUrl: 'combo-select.component.html', styleUrls: ['combo-select.component.css'], directives: [common_1.COMMON_DIRECTIVES, core_2.IX_DIRECTIVES], pipes: [common_1.COMMON_PIPES], providers: [new core_2.NgModelInputValueAccessor(ComboSelectComponent)] }), __metadata('design:paramtypes', []) ], ComboSelectComponent); return ComboSelectComponent; }(combo_select_1.ComboSelect)); exports.ComboSelectComponent = ComboSelectComponent; //# sourceMappingURL=combo-select.component.js.map