I'm using a jQuery plugin to replace select-boxes and I want to add a hidden input if selecting an item while the shift key is held when pressing enter. My problem is that the select plugin listener is happening before my keydown listener. Is there a way to make my first on()
below execute before my second on()
? Or is there a way to check inside the second on()
if the shift key is being held? e.shiftKey
gives me undefined
if I put it inside the second on()
. Thanks for ideas!
var shiftHeld = false;
$(document).on('keydown', function(e) {
if(e.which == 13) {
shiftHeld = e.shiftKey;
}
});
$menu = $('#menu').select2();
$menu.on('select2:close', function (e) {
if(shiftHeld) { $('#form').append('<input type="hidden" name="shift" value="1" />'); }
form.submit();
});