Skip to content

Commit 64aae38

Browse files
committed
DatePicker: Get selectedDay by data instead DOM html
`selectDay()` use jQuery `html()` method on `td` cell to get the day value from DOM, but when user use translator or other extension, it return NaN value because the cell can contains non excepted content. We must use data- attribute to ensure that value cannot be altered. - https://jqueryui.com/resources/demos/datepicker/localization.html - https://translate.google.com/translate?hl=en&sl=fr&tl=pl&u=https%3A%2F%2Fjqueryui.com%2Fresources%2Fdemos%2Fdatepicker%2Flocalization.html We got ```html <td class=" " data-handler="selectDay" data-event="click" data-month="0" data-year="2021"> <a class="ui-state-default" href="#"> <font style="vertical-align: inherit;"><font style="vertical-align: inherit;">22</font></font> </a> </td> ``` instead of ``` <td class=" " data-handler="selectDay" data-event="click" data-month="0" data-year="2021"> <a class="ui-state-default" href="#">22</a> </td> ``` so this cannot work correctly ``` inst.selectedDay = inst.currentDay = $( "a", td ).html(); ``` I think it's not a good practice to get value from html DOM element
1 parent 91b6fc3 commit 64aae38

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ui/widgets/datepicker.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ $.extend( Datepicker.prototype, {
10361036
}
10371037

10381038
inst = this._getInst( target[ 0 ] );
1039-
inst.selectedDay = inst.currentDay = $( "a", td ).html();
1039+
inst.selectedDay = inst.currentDay = $( "a", td ).data( "date" );
10401040
inst.selectedMonth = inst.currentMonth = month;
10411041
inst.selectedYear = inst.currentYear = year;
10421042
this._selectDate( id, this._formatDate( inst,
@@ -1816,7 +1816,7 @@ $.extend( Datepicker.prototype, {
18161816
( printDate.getTime() === today.getTime() ? " ui-state-highlight" : "" ) +
18171817
( printDate.getTime() === currentDate.getTime() ? " ui-state-active" : "" ) + // highlight selected day
18181818
( otherMonth ? " ui-priority-secondary" : "" ) + // distinguish dates from other months
1819-
"' href='#'>" + printDate.getDate() + "</a>" ) ) + "</td>"; // display selectable date
1819+
"' href='#' data-date='" + printDate.getDate() + "'>" + printDate.getDate() + "</a>" ) ) + "</td>"; // display selectable date
18201820
printDate.setDate( printDate.getDate() + 1 );
18211821
printDate = this._daylightSavingAdjust( printDate );
18221822
}

0 commit comments

Comments
 (0)