]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: Get selectedDay from data-date instead of element contents
authorc-lambert <58025159+c-lambert@users.noreply.github.com>
Mon, 12 Jul 2021 07:41:41 +0000 (09:41 +0200)
committerGitHub <noreply@github.com>
Mon, 12 Jul 2021 07:41:41 +0000 (09:41 +0200)
This makes datepicker work fine even if translation software modifies texts on the page.

Closes gh-1943

ui/widgets/datepicker.js

index 7dbcf3de7abeb112094c901f957cc8db4438318f..9ca29a0db5bc5747077a1f8b0162a2a20891dad3 100644 (file)
@@ -1080,7 +1080,7 @@ $.extend( Datepicker.prototype, {
                }
 
                inst = this._getInst( target[ 0 ] );
-               inst.selectedDay = inst.currentDay = $( "a", td ).html();
+               inst.selectedDay = inst.currentDay = parseInt( $( "a", td ).attr( "data-date" ) );
                inst.selectedMonth = inst.currentMonth = month;
                inst.selectedYear = inst.currentYear = year;
                this._selectDate( id, this._formatDate( inst,
@@ -1932,6 +1932,7 @@ $.extend( Datepicker.prototype, {
                                                        ( printDate.getTime() === currentDate.getTime() ? " ui-state-active" : "" ) + // highlight selected day
                                                        ( otherMonth ? " ui-priority-secondary" : "" ) + // distinguish dates from other months
                                                        "' href='#' aria-current='" + ( printDate.getTime() === currentDate.getTime() ? "true" : "false" ) + // mark date as selected for screen reader
+                                                       "' data-date='" + printDate.getDate() + // store date as data
                                                        "'>" + printDate.getDate() + "</a>" ) ) + "</td>"; // display selectable date
                                                printDate.setDate( printDate.getDate() + 1 );
                                                printDate = this._daylightSavingAdjust( printDate );