parmarmayur9090 / jquery-datepicker

Automatically exported from code.google.com/p/jquery-datepicker
0 stars 0 forks source link

Add up/down key support #242

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Just a suggestion for an enhancement to add keyboard support to increment or 
decrement the date.  I modified the script for my own purposes, and you're 
welcome to use or improve on it.  I added this to the datePicker function below 
the "if (s.clickInput) {" block.  Other possible additions would be page 
up/down to change by month or year.  The option is enabled by calling 
"$('.date-pick').datePicker({allowKeyboard: true});"

if (s.allowKeyboard) {
    $this.bind('keypress', function(event) {
    var d = Date.fromString(this.value);
    switch(event.keyCode) {
        case 38:
        if (d < controller.endDate)
            this.value = d.addDays(1).asString();
        break;
        case 40:
        if(d > controller.startDate)
            this.value = d.addDays(-1).asString();
        break;
    }
    });
}

Original issue reported on code.google.com by one...@gmail.com on 5 Oct 2010 at 5:41

GoogleCodeExporter commented 8 years ago
Just noticed a small flaw with my code.  It doesn't update the internal 
selected value without

controller.setSelected(d, true, true);

I put it in each case block just to make sure we don't do unneeded calls for 
ignored keys.

Original comment by one...@gmail.com on 9 Oct 2010 at 7:35