Skip to content

Commit

Permalink
Merge pull request #57 from billn6/main
Browse files Browse the repository at this point in the history
Update digit-only.directive.ts
  • Loading branch information
changhuixu authored Sep 7, 2021
2 parents 7ad10f3 + bc4bf3d commit 4661e02
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions projects/uiowa/digit-only/src/lib/digit-only.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class DigitOnlyDirective implements OnChanges {
@Input() decimal = false;
@Input() decimalSeparator = '.';
@Input() allowNegatives= false;
@Input() allowPaste = true;
@Input() negativeSign = '-';
@Input() min = -Infinity;
@Input() max = Infinity;
Expand Down Expand Up @@ -132,23 +133,29 @@ export class DigitOnlyDirective implements OnChanges {
e.preventDefault();
}
}

@HostListener('paste', ['$event'])
onPaste(event: any): void {
let pastedInput: string = '';
if ((window as { [key: string]: any })['clipboardData']) {
// Browser is IE
pastedInput = (window as { [key: string]: any })['clipboardData'].getData(
'text'
);
} else if (event.clipboardData && event.clipboardData.getData) {
// Other browsers
pastedInput = event.clipboardData.getData('text/plain');
}
if (this.allowPaste === true) {
let pastedInput: string = '';
if ((window as { [key: string]: any })['clipboardData']) {
// Browser is IE
pastedInput = (window as { [key: string]: any })['clipboardData'].getData(
'text'
);
} else if (event.clipboardData && event.clipboardData.getData) {
// Other browsers
pastedInput = event.clipboardData.getData('text/plain');
}

this.pasteData(pastedInput);
event.preventDefault();
this.pasteData(pastedInput);
event.preventDefault();
} else { // this prevents the paste
event.preventDefault();
event.stopPropagation();
}
}


@HostListener('drop', ['$event'])
onDrop(event: DragEvent): void {
Expand Down

0 comments on commit 4661e02

Please sign in to comment.