-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Datepicker: Get selectedDay from data-date instead of element contents #1943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for the PR! @fnagel Are you able to review this? |
Looks like a replace of @mgol What do you think? @c-lambert Would you mind squashing the CGL fix commit into the actual one? |
7643a7d
to
64aae38
Compare
Hello ! I think this is more safe too. data- attributes is indeed already used in the template for year and month data. :1813
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fnagel Data attributes make sense to me considering they're also used for year/month/etc. data. However, looking at the code, Datepicker reads the attributes directly via native getAttribute
instead of using .data()
which just pulls initial attribute value and then ignores subsequent changes to the attribute.
@c-lambert Such a change requires adding a unit test; you can look at the existing test files for similar data-*
-related tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the commit title from "DatePicker: Get..." ti "Datepicker: Get...". Otherwise good to be merged IMO.
@mgol I think we can skip the tests here, as its actually a tiny change which should to be covered my existing tests.
@fnagel We don't have tests ensuring we don't read the element contents but I guess we also don't have such tests for other fields so I guess we're good here. I wouldn't block the RP over the title, I can fix that during the squash & merge. If that's your only concern, could you withdraw the objection? I'll be sure to modify the component during the merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Withdrawing my objections per Felix's comment; LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the PR again & I have one important remark.
ui/widgets/datepicker.js
Outdated
@@ -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" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, now that I look at it again, we should read the attribute directly instead of using data
. .data(key)
pulls the initial value from the data-key
attribute but that's it; it then keeps its state and disregards the attribute. It sounds we want the attribute to be the soruce of truth here.
Most other similar places in this widget use +this.getAttribute( "data-something" )
. I'm not sure if skipping jQuery's .attr()
had any reason but we should either use getAttribute
or attr
here & cast the value to number.
@c-lambert Hey, do you want to try to update the PR with my feedback? If you don't have time, we may try to do it ourselves. |
3321bd4
to
8663ef3
Compare
Ok done ! I also parsed the return value of attr() method to int. |
@c-lambert Thanks! Can you also rebase over latest |
@c-lambert I see you upvoted my comment. Let me know when you rebase and I'll merge the PR. Thanks! |
I can do it this weekend ! |
8663ef3
to
2c79601
Compare
2c79601
to
57624b0
Compare
Hello it's done ! |
Landed, thanks! |
selectDay()
use jQueryhtml()
method ontd
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.We got
instead of
so this cannot work correctly
I think it's not a good practice to get value from html DOM element