]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: Make select and change event pass the current value
authorFelix Nagel <info@felixnagel.com>
Sun, 11 Dec 2016 22:10:46 +0000 (23:10 +0100)
committerFelix Nagel <info@felixnagel.com>
Sat, 21 Jan 2017 12:49:35 +0000 (13:49 +0100)
tests/unit/datepicker/events.js
ui/widgets/datepicker.js

index 05ae7ed4d98f2a21a51038a752208e19e0145e7d..76615084caaada84a1bb8f9b76df95cf0ad6aab9 100644 (file)
@@ -44,18 +44,19 @@ QUnit.test( "beforeOpen", function( assert ) {
 } );
 
 QUnit.test( "change", function( assert ) {
-       assert.expect( 4 );
+       assert.expect( 6 );
 
        var shouldFire;
 
        this.element.datepicker( {
-               change: function( event ) {
+               change: function( event, ui ) {
                        assert.ok( shouldFire, "change event fired" );
                        assert.equal(
                                event.type,
                                "datepickerchange",
                                "change event"
                        );
+                       assert.equal( $.type( ui.value ), "date", "value is a date object" );
                }
        } );
 
@@ -121,19 +122,20 @@ QUnit.test( "open", function( assert ) {
 
 QUnit.test( "select", function( assert ) {
        var ready = assert.async();
-       assert.expect( 4 );
+       assert.expect( 6 );
 
        var message = "",
                that = this;
 
        this.element.datepicker( {
-               select: function( event ) {
+               select: function( event, ui ) {
                        assert.ok( true, "select event fired " + message );
                        assert.equal(
                                event.originalEvent.type,
                                "calendarselect",
                                "select originalEvent " + message
                        );
+                       assert.equal( $.type( ui.value ), "date", "value is a date object" );
                }
        } );
 
index b489fe9b7efe7027ecc56e52517885416773d888..1325434d3d01a71cde368634c7e72142d0bae0b2 100644 (file)
@@ -111,14 +111,18 @@ var widget = $.widget( "ui.datepicker", {
                        .calendar( $.extend( {}, this.options, {
                                value: this._parse( this.element.val() ),
                                change: function( event ) {
-                                       that._trigger( "change", event );
+                                       that._trigger( "change", event, {
+                                               value: that.calendarInstance.valueAsDate()
+                                       } );
                                },
                                select: function( event ) {
                                        that.element.val( that.calendarInstance.value() );
                                        that.close();
                                        event.preventDefault();
                                        that._focusTrigger();
-                                       that._trigger( "select", event );
+                                       that._trigger( "select", event, {
+                                               value: that.calendarInstance.valueAsDate()
+                                       } );
 
                                        return false;
                                }
@@ -183,7 +187,9 @@ var widget = $.widget( "ui.datepicker", {
                        this.suppressExpandOnFocus = false;
                },
                change: function( event ) {
-                       this._trigger( "change", event );
+                       this._trigger( "change", event, {
+                               value: this.calendarInstance.valueAsDate()
+                       } );
                }
        },