Added input validation

This commit is contained in:
NejcZdovc
2016-11-17 08:10:31 +01:00
committed by József Farkas
parent 11c79fd312
commit 1ea1d0c2a2
4 changed files with 27 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
import { Component, Input } from '@angular/core';
import { Component, ElementRef, Input, Renderer, ViewChild } from '@angular/core';
import { Store } from '@ngrx/store';
@@ -14,8 +14,10 @@ import { KeymapActions } from '../../../store/actions';
})
export class KeymapHeaderComponent {
@Input() keymap: Keymap;
@ViewChild('name') keymapName: ElementRef;
@ViewChild('abbr') keymapAbbr: ElementRef;
constructor(private store: Store<AppState>) { }
constructor(private store: Store<AppState>, private renderer: Renderer) { }
setDefault() {
if (!this.keymap.isDefault) {
@@ -32,10 +34,20 @@ export class KeymapHeaderComponent {
}
editKeymapName(name: string) {
if (name.length === 0) {
this.renderer.setElementProperty(this.keymapName.nativeElement, 'value', this.keymap.name);
return;
}
this.store.dispatch(KeymapActions.editKeymapName(this.keymap.abbreviation, name));
}
editKeymapAbbr(newAbbr: string) {
if (newAbbr.length !== 3) {
this.renderer.setElementProperty(this.keymapAbbr.nativeElement, 'value', this.keymap.abbreviation);
return;
}
newAbbr = newAbbr.toUpperCase();
this.store.dispatch(KeymapActions.editKeymapAbbr(this.keymap.abbreviation, newAbbr));
}