]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: Update the picker as the user types valid dates
authorTJ VanToll <tj.vantoll@gmail.com>
Fri, 3 Jan 2014 14:55:06 +0000 (09:55 -0500)
committerScott González <scott.gonzalez@gmail.com>
Thu, 29 Jan 2015 22:47:50 +0000 (17:47 -0500)
tests/unit/datepicker/datepicker_core.js
ui/datepicker.js

index c9d0403b240e945c9d1db65dcf43b13bb190f801..377c4c201dd6f011ecaf91f8ed434fdab2677df5 100644 (file)
@@ -218,7 +218,7 @@ asyncTest( "baseStructure", function() {
 });
 
 test( "Keyboard handling", function() {
-       expect( 8 );
+       expect( 9 );
        var input = $( "#datepicker" ).datepicker(),
                instance = input.datepicker( "instance" ),
                date = new Date();
@@ -260,6 +260,11 @@ test( "Keyboard handling", function() {
        TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
                "Keystroke esc - abandoned" );
 
+       input.val( "1/2/14" )
+               .simulate( "keyup" );
+       TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 2 ),
+               "Picker updated as user types into input" );
+
        input.datepicker( "destroy" );
 });
 
index 8711b5329d0ced75f6a90df0ea58866f36c82d1b..5a3d9a191324ae02db047b5430663ea9a3f76343 100644 (file)
@@ -232,6 +232,12 @@ $.widget( "ui.datepicker", {
                                                break;
                                }
                        },
+                       keyup: function() {
+                               if ( this.isValid() && !this.inline ) {
+                                       this.date.setTime( this.element.val() ).select();
+                                       this.refresh();
+                               }
+                       },
                        mousedown: function( event ) {
                                if (this.isOpen) {
                                        suppressExpandOnFocus = true;