]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: Make sure altField is treated as a CSS selector
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Tue, 4 May 2021 11:30:06 +0000 (13:30 +0200)
committerGitHub <noreply@github.com>
Tue, 4 May 2021 11:30:06 +0000 (13:30 +0200)
Closes gh-1954

tests/unit/datepicker/options.js
ui/widgets/datepicker.js

index d70220955a5ab4197bf4081987b3278f501e8ca0..e5e938a0f7b47d49d377a6672a708b7f2b0eff90 100644 (file)
@@ -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: "<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 ) {
index 441170c97786e53c0115b5f63273ddabc0401518..f03e075cd0266ff797be23b4ec6fa42494b1b050 100644 (file)
@@ -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 );
                }
        },