Skip to content

Commit

Permalink
Datepicker: Make sure altField is treated as a CSS selector
Browse files Browse the repository at this point in the history
Closes gh-1954
  • Loading branch information
mgol committed May 4, 2021
1 parent 9380d27 commit 3285086
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions tests/unit/datepicker/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,10 @@ QUnit.test( "setDate", function( assert ) {
} );

QUnit.test( "altField", function( assert ) {
assert.expect( 10 );
var inp = testHelper.init( "#inp" ),
assert.expect( 11 );

var done = assert.async(),
inp = testHelper.init( "#inp" ),
alt = $( "#alt" );

// No alternate field set
Expand Down Expand Up @@ -664,6 +666,22 @@ QUnit.test( "altField", function( assert ) {
inp.simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.END } );
assert.equal( inp.val(), "", "Alt field - dp - ctrl+end" );
assert.equal( alt.val(), "", "Alt field - alt - ctrl+end" );

// HTML instead of selector
alt.val( "" );
try {
inp.datepicker( "option", {
altField: "<img onerror='window.globalAltField=true' src='/404' />",
altFormat: "yy-mm-dd"
} ).val( "06/04/2008" ).datepicker( "show" );
inp.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
} catch ( e ) {}

setTimeout( function() {
assert.equal( window.globalAltField, undefined, "altField treated as a selector" );
delete window.globalAltField;
done();
}, 500 );
} );

QUnit.test( "autoSize", function( assert ) {
Expand Down
2 changes: 1 addition & 1 deletion ui/widgets/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ $.extend( Datepicker.prototype, {
altFormat = this._get( inst, "altFormat" ) || this._get( inst, "dateFormat" );
date = this._getDate( inst );
dateStr = this.formatDate( altFormat, date, this._getFormatConfig( inst ) );
$( altField ).val( dateStr );
$( document ).find( altField ).val( dateStr );
}
},

Expand Down

0 comments on commit 3285086

Please sign in to comment.