Skip to content

Make buttons respond to Enter and Esc keys #286

Description

@cfcoderatcodefactory

Found nothing in the documentation about this.
I want to be able to bind the Enter and Esc keys to the different buttons in the various Vex pop-up variants.
Example Code (which doesn’t work):
vex.dialog.buttons.YES.text = 'Continue';
vex.dialog.buttons.NO.text = 'Cancel';
vex.dialog.confirm({
message: 'Any kind of question',
callback: function(value) {
if (value) {
console.log('confirm clicked');
function2invoke(param1, param2);
}
else {
console.log('cancel clicked');
differentFunction2invoke(param1, param2);
}
}
})
// make OK button respond to enter key and cancel button respond to escape key
$(document).bind("keyup.key13", function(event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
console.log('keycode clicked: ' + keycode);
if (keycode == '13') {
console.log('confirm clicked');
function2invoke(param1, param2);
}
});
$(document).bind("keyup.key27", function(event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
console.log('keycode clicked: ' + keycode);
if (keycode == '27') {
console.log('cancel clicked');
differentFunction2invoke(param1, param2);
}
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions