From 64aae384341fa9f45f627c123acd6b92f0c912fe Mon Sep 17 00:00:00 2001 From: c-lambert <58025159+c-lambert@users.noreply.github.com> Date: Thu, 21 Jan 2021 14:03:19 +0100 Subject: [PATCH] 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 22 ``` instead of ``` 22 ``` 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 --- ui/widgets/datepicker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/widgets/datepicker.js b/ui/widgets/datepicker.js index 441170c9778..41ca503db4b 100644 --- a/ui/widgets/datepicker.js +++ b/ui/widgets/datepicker.js @@ -1036,7 +1036,7 @@ $.extend( Datepicker.prototype, { } inst = this._getInst( target[ 0 ] ); - inst.selectedDay = inst.currentDay = $( "a", td ).html(); + inst.selectedDay = inst.currentDay = $( "a", td ).data( "date" ); inst.selectedMonth = inst.currentMonth = month; inst.selectedYear = inst.currentYear = year; this._selectDate( id, this._formatDate( inst, @@ -1816,7 +1816,7 @@ $.extend( Datepicker.prototype, { ( printDate.getTime() === today.getTime() ? " ui-state-highlight" : "" ) + ( printDate.getTime() === currentDate.getTime() ? " ui-state-active" : "" ) + // highlight selected day ( otherMonth ? " ui-priority-secondary" : "" ) + // distinguish dates from other months - "' href='#'>" + printDate.getDate() + "" ) ) + ""; // display selectable date + "' href='#' data-date='" + printDate.getDate() + "'>" + printDate.getDate() + "" ) ) + ""; // display selectable date printDate.setDate( printDate.getDate() + 1 ); printDate = this._daylightSavingAdjust( printDate ); }