From 32850869d308d5e7c9bf3e3b4d483ea886d373ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Tue, 4 May 2021 13:30:06 +0200 Subject: [PATCH] Datepicker: Make sure altField is treated as a CSS selector Closes gh-1954 --- tests/unit/datepicker/options.js | 22 ++++++++++++++++++++-- ui/widgets/datepicker.js | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/unit/datepicker/options.js b/tests/unit/datepicker/options.js index d70220955..e5e938a0f 100644 --- a/tests/unit/datepicker/options.js +++ b/tests/unit/datepicker/options.js @@ -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 @@ -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: "", + 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 ) { diff --git a/ui/widgets/datepicker.js b/ui/widgets/datepicker.js index 441170c97..f03e075cd 100644 --- a/ui/widgets/datepicker.js +++ b/ui/widgets/datepicker.js @@ -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 ); } }, -- 2.39.5