I created this function to add a key handler to dateboxes that will increment /decrement the date when the up or down arrows are pressed. This code works when I enter it in the developer console after loading the page, but not when I include it in the page. I tried including it in the document.ready function and then placing it at the bottom of the page but it doesn't work either way - it does nothing. Where do I need to put this in order for it to work?
Also, when figuring out how to do this, I found that in this code, $(this) returns the textbox that EasyUI creates internally, not the actual datebox component, and therefore it's necessary to use val() rather than getText or setText. Is there a way to get the datebox component here? It's not really important but would make the code more understandable.
$('.easyui-datebox').datebox({
inputEvents:$.extend({},$.fn.datebox.defaults.inputEvents,{
keyup:function(e){
if ((e.which == 38) || (e.which==40)){
var days=(e.which==38) ? 1 : -1;
var d1 = moment($(this).val()).add(days, 'days'); // uses moment.js date library
var d2 =d1.format('MM/DD/YYYY');
$(this).val(d2);
}
}
})
})