Skip to content

Commit 3285086

Browse files
authored
Datepicker: Make sure altField is treated as a CSS selector
Closes gh-1954
1 parent 9380d27 commit 3285086

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

tests/unit/datepicker/options.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,10 @@ QUnit.test( "setDate", function( assert ) {
623623
} );
624624

625625
QUnit.test( "altField", function( assert ) {
626-
assert.expect( 10 );
627-
var inp = testHelper.init( "#inp" ),
626+
assert.expect( 11 );
627+
628+
var done = assert.async(),
629+
inp = testHelper.init( "#inp" ),
628630
alt = $( "#alt" );
629631

630632
// No alternate field set
@@ -664,6 +666,22 @@ QUnit.test( "altField", function( assert ) {
664666
inp.simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.END } );
665667
assert.equal( inp.val(), "", "Alt field - dp - ctrl+end" );
666668
assert.equal( alt.val(), "", "Alt field - alt - ctrl+end" );
669+
670+
// HTML instead of selector
671+
alt.val( "" );
672+
try {
673+
inp.datepicker( "option", {
674+
altField: "<img onerror='window.globalAltField=true' src='/404' />",
675+
altFormat: "yy-mm-dd"
676+
} ).val( "06/04/2008" ).datepicker( "show" );
677+
inp.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
678+
} catch ( e ) {}
679+
680+
setTimeout( function() {
681+
assert.equal( window.globalAltField, undefined, "altField treated as a selector" );
682+
delete window.globalAltField;
683+
done();
684+
}, 500 );
667685
} );
668686

669687
QUnit.test( "autoSize", function( assert ) {

ui/widgets/datepicker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ $.extend( Datepicker.prototype, {
10891089
altFormat = this._get( inst, "altFormat" ) || this._get( inst, "dateFormat" );
10901090
date = this._getDate( inst );
10911091
dateStr = this.formatDate( altFormat, date, this._getFormatConfig( inst ) );
1092-
$( altField ).val( dateStr );
1092+
$( document ).find( altField ).val( dateStr );
10931093
}
10941094
},
10951095

0 commit comments

Comments
 (0)