Skip to content

Commit

Permalink
Revert "#58 Allow special chars by choice"
Browse files Browse the repository at this point in the history
  • Loading branch information
changhuixu authored Oct 7, 2021
1 parent f02b89c commit 89e924d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,6 @@ export class YourModule { }
digitOnly
decimal="true"
/>

// Digit Only input allows keypress of specific keys
<input
type="text"
name="calculate"
placeholder="00"
inputmode="numeric"
pattern="[0-9]*"
digitOnly
allowKeys="Slash,BracketRight,NumpadAdd,NumpadSubtract"
/>
```

### `mask` directive usage
Expand Down
11 changes: 0 additions & 11 deletions projects/uiowa/digit-only/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,6 @@ export class YourModule { }
digitOnly
decimal="true"
/>

// Digit Only input allows keypress of specific keys
<input
type="text"
name="calculate"
placeholder="00"
inputmode="numeric"
pattern="[0-9]*"
digitOnly
allowKeys="Slash,BracketRight,NumpadAdd,NumpadSubtract"
/>
```

### `mask` directive usage
Expand Down
13 changes: 4 additions & 9 deletions projects/uiowa/digit-only/src/lib/digit-only.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ export class DigitOnlyDirective implements OnChanges {
'Copy',
'Paste',
];
private allowedKeys: Array<string> = [];

@Input() decimal = false;
@Input() decimalSeparator = '.';
@Input() allowNegatives = false;
@Input() allowNegatives= false;
@Input() allowPaste = true;
@Input() negativeSign = '-';
@Input() min = -Infinity;
@Input() max = Infinity;
@Input() pattern?: string | RegExp;
@Input() allowKeys: string = "";
private regex: RegExp | null = null;
inputElement: HTMLInputElement;

Expand All @@ -46,8 +44,6 @@ export class DigitOnlyDirective implements OnChanges {
}

ngOnChanges(changes: SimpleChanges): void {
this.allowedKeys = this.allowKeys.split(',')

if (changes.pattern) {
this.regex = this.pattern ? RegExp(this.pattern) : null;
}
Expand Down Expand Up @@ -79,7 +75,6 @@ export class DigitOnlyDirective implements OnChanges {
onKeyDown(e: KeyboardEvent): any {
if (
this.navigationKeys.indexOf(e.key) > -1 || // Allow: navigation keys: backspace, delete, arrows etc.
this.allowedKeys.indexOf(e.code) > -1 || // Allow custom keys
((e.key === 'a' || e.code === 'KeyA') && e.ctrlKey === true) || // Allow: Ctrl+A
((e.key === 'c' || e.code === 'KeyC') && e.ctrlKey === true) || // Allow: Ctrl+C
((e.key === 'v' || e.code === 'KeyV') && e.ctrlKey === true) || // Allow: Ctrl+V
Expand Down Expand Up @@ -138,7 +133,7 @@ export class DigitOnlyDirective implements OnChanges {
e.preventDefault();
}
}

@HostListener('paste', ['$event'])
onPaste(event: any): void {
if (this.allowPaste === true) {
Expand All @@ -155,12 +150,12 @@ export class DigitOnlyDirective implements OnChanges {

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


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

0 comments on commit 89e924d

Please sign in to comment.