Created
May 23, 2018 11:03
-
-
Save wiseoldman/a88aef62a3c2b3c04aac5f06a2299572 to your computer and use it in GitHub Desktop.
[BlockInputKeys] Block an array of keys on inputs #form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BlockInputKeys { | |
constructor(INPUT_TYPE, BLOCKED_KEYS) { | |
this.INPUT_TYPE = INPUT_TYPE; | |
this.BLOCKED_KEYS = BLOCKED_KEYS; | |
this.NUMBER_INPUTS = document.querySelectorAll(this.INPUT_TYPE); | |
this.init(); | |
} | |
init() { | |
for (let i = 0; i < this.NUMBER_INPUTS.length; i++) { | |
const INPUT = this.NUMBER_INPUTS[i]; | |
INPUT.addEventListener('keydown', (e) => { | |
if (this.BLOCKED_KEYS.indexOf(e.which) !== -1) { | |
e.preventDefault(); | |
} | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment