From: Felix Nagel Date: Sun, 11 Dec 2016 22:10:46 +0000 (+0100) Subject: Datepicker: Make select and change event pass the current value X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8b864309f646f67f7fca88f87a9dea4fe5526aba;p=jquery-ui.git Datepicker: Make select and change event pass the current value --- diff --git a/tests/unit/datepicker/events.js b/tests/unit/datepicker/events.js index 05ae7ed4d..76615084c 100644 --- a/tests/unit/datepicker/events.js +++ b/tests/unit/datepicker/events.js @@ -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" ); } } ); diff --git a/ui/widgets/datepicker.js b/ui/widgets/datepicker.js index b489fe9b7..1325434d3 100644 --- a/ui/widgets/datepicker.js +++ b/ui/widgets/datepicker.js @@ -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() + } ); } },