summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/chart-wizard/numbers-only.directive.ts
blob: 4f56ff5e693ec6eb6230d569b4ce2f3231bae6cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import {Directive, ElementRef, HostListener} from '@angular/core';

@Directive({
  selector: '[appNumbersOnly]'
})
export class NumbersOnlyDirective {

    constructor(private _el: ElementRef) { }

    @HostListener('input', ['$event']) onInputChange(event) {
        const initialValue = this._el.nativeElement.value;
        this._el.nativeElement.value = initialValue.replace(/[^0-9]*/g, '');
        if ( initialValue !== this._el.nativeElement.value) {
            event.stopPropagation();
        }
    }

}