Skip to content

Instantly share code, notes, and snippets.

@drewbrokke
Created June 12, 2014 17:57
Show Gist options
  • Save drewbrokke/3a7161e7ffd249790cb4 to your computer and use it in GitHub Desktop.
Save drewbrokke/3a7161e7ffd249790cb4 to your computer and use it in GitHub Desktop.
_handleKeypressEvent: function(event) {
var instance = this;
var target = event.target;
var type = target.get('nodeType');
console.log("event: ", event);
var field = target;
var keyCode = event.keyCode;
if (target.hasClass("form-builder-field-node")) {
if ((keyCode === 27) ||
(keyCode === 13 && !target.hasClass("field-textarea")) ||
(target.hasClass("field-textarea") && keyCode === 13 && event.ctrlKey === true)) {
target.ancestor(".form-builder-field").focus();
}
}
if (target.hasClass("form-builder-field")) {
if (keyCode === 39 || keyCode === 40) { // Down Arrow
next = field.next();
if (next !== null) {
next.focus();
}
}
else if (keyCode === 37 || keyCode === 38) { // Up Arrow
previous = field.previous();
if (previous !== null) {
previous.focus();
}
}
else if (keyCode === 13) { // Enter Key
field.one(".form-builder-field-node").focus();
}
}
event.stopPropagation();
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment