mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Calendar: Add change event
This commit is contained in:
parent
6f9d266339
commit
9fc83a085c
@ -35,6 +35,7 @@ common.testWidget( "calendar", {
|
||||
value: null,
|
||||
|
||||
// callbacks
|
||||
change: null,
|
||||
create: null,
|
||||
select: null
|
||||
}
|
||||
|
@ -10,6 +10,42 @@ module( "calendar: events", {
|
||||
}
|
||||
} );
|
||||
|
||||
test( "change", function() {
|
||||
expect( 6 );
|
||||
|
||||
var shouldFire, eventType;
|
||||
|
||||
this.element.calendar( {
|
||||
change: function( event ) {
|
||||
ok( shouldFire, "change event fired" );
|
||||
equal(
|
||||
event.type,
|
||||
"calendarchange",
|
||||
"change event"
|
||||
);
|
||||
equal(
|
||||
event.originalEvent.type,
|
||||
eventType,
|
||||
"change originalEvent on calendar button " + eventType
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
||||
shouldFire = true;
|
||||
eventType = "mousedown";
|
||||
this.element.find( "tbody button" ).last().simulate( eventType );
|
||||
|
||||
shouldFire = true;
|
||||
eventType = "keydown";
|
||||
testHelper.focusGrid( this.element )
|
||||
.simulate( eventType, { keyCode: $.ui.keyCode.HOME } )
|
||||
.simulate( eventType, { keyCode: $.ui.keyCode.ENTER } );
|
||||
|
||||
shouldFire = false;
|
||||
eventType = "mousedown";
|
||||
this.element.find( "tbody button" ).first().simulate( eventType );
|
||||
} );
|
||||
|
||||
asyncTest( "select", function() {
|
||||
expect( 6 );
|
||||
|
||||
|
@ -42,6 +42,7 @@ common.testWidget( "datepicker", {
|
||||
|
||||
// callbacks
|
||||
beforeOpen: null,
|
||||
change: null,
|
||||
close: null,
|
||||
create: null,
|
||||
open: null,
|
||||
|
@ -42,6 +42,35 @@ test( "beforeOpen", function() {
|
||||
.datepicker( "open" );
|
||||
} );
|
||||
|
||||
test( "change", function() {
|
||||
expect( 4 );
|
||||
|
||||
var shouldFire;
|
||||
|
||||
this.element.datepicker( {
|
||||
change: function( event ) {
|
||||
ok( shouldFire, "change event fired" );
|
||||
equal(
|
||||
event.type,
|
||||
"datepickerchange",
|
||||
"change event"
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
||||
shouldFire = true;
|
||||
this.element.datepicker( "open" );
|
||||
this.widget.find( "tbody button" ).eq( 1 ).simulate( "mousedown" );
|
||||
|
||||
shouldFire = false;
|
||||
this.element.datepicker( "open" );
|
||||
this.widget.find( "tbody button" ).eq( 1 ).simulate( "mousedown" );
|
||||
|
||||
shouldFire = true;
|
||||
this.element.datepicker( "open" );
|
||||
this.widget.find( "tbody button" ).eq( 2 ).simulate( "mousedown" );
|
||||
} );
|
||||
|
||||
test( "close", function() {
|
||||
expect( 4 );
|
||||
|
||||
@ -71,7 +100,7 @@ test( "close", function() {
|
||||
shouldFire = false;
|
||||
this.element.datepicker( "open" );
|
||||
shouldFire = true;
|
||||
this.element.datepicker( "widget" ).find( "tbody tr:first button:first" ).simulate( "mousedown" );
|
||||
this.widget.find( "tbody tr:first button:first" ).simulate( "mousedown" );
|
||||
} );
|
||||
|
||||
test( "open", function() {
|
||||
|
@ -72,6 +72,7 @@ return $.widget( "ui.calendar", {
|
||||
value: null,
|
||||
|
||||
// callbacks
|
||||
change: null,
|
||||
select: null
|
||||
},
|
||||
|
||||
@ -125,6 +126,8 @@ return $.widget( "ui.calendar", {
|
||||
},
|
||||
|
||||
_select: function( event ) {
|
||||
var oldValue = this.options.value ? this.options.value.getTime() : "";
|
||||
|
||||
this._setOption( "value", new Date( $( event.currentTarget ).data( "timestamp" ) ) );
|
||||
this._updateDayElement( "ui-state-active" );
|
||||
|
||||
@ -133,6 +136,10 @@ return $.widget( "ui.calendar", {
|
||||
this.activeDescendant.closest( this.grid ).focus();
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if ( oldValue !== this.options.value.getTime() ) {
|
||||
this._trigger( "change", event );
|
||||
}
|
||||
},
|
||||
|
||||
_handleKeydown: function( event ) {
|
||||
|
@ -51,6 +51,7 @@ var widget = $.widget( "ui.datepicker", {
|
||||
|
||||
// callbacks
|
||||
beforeOpen: null,
|
||||
change: null,
|
||||
close: null,
|
||||
open: null,
|
||||
select: null
|
||||
@ -104,6 +105,9 @@ var widget = $.widget( "ui.datepicker", {
|
||||
this.calendarInstance = this.calendar
|
||||
.calendar( $.extend( {}, this.options, {
|
||||
value: this._parse( this.element.val() ),
|
||||
change: function( event ) {
|
||||
that._trigger( "change", event );
|
||||
},
|
||||
select: function( event ) {
|
||||
that.element.val( that.calendarInstance.value() );
|
||||
that.close();
|
||||
@ -172,6 +176,9 @@ var widget = $.widget( "ui.datepicker", {
|
||||
},
|
||||
blur: function() {
|
||||
this.suppressExpandOnFocus = false;
|
||||
},
|
||||
change: function( event ) {
|
||||
this._trigger( "change", event );
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user