Skip to content

Instantly share code, notes, and snippets.

@wiseoldman
Created May 23, 2018 11:03
Show Gist options
  • Save wiseoldman/a88aef62a3c2b3c04aac5f06a2299572 to your computer and use it in GitHub Desktop.
Save wiseoldman/a88aef62a3c2b3c04aac5f06a2299572 to your computer and use it in GitHub Desktop.
[BlockInputKeys] Block an array of keys on inputs #form
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