Skip to content
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

Fix #3966 - Datepicker does not respect locale on first load #4085

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

carolinebelt
Copy link

Datepicker now displays correct min-date after clicking out of widget and back into it (second load).

Copy link

cla-bot bot commented Apr 17, 2024

Hey there! :) Thank you very much for offering a contribution to pretix! For legal reasons, we need you to sign a Contributor License Agreement in order to be able to merge the code. Sorry for the hassle :( Please download the agreement from https://pretix.eu/about/en/cla and send a signed copy to [email protected]. Feel free to also contact us there or via comments here if you have any questions!

@raphaelm raphaelm requested a review from wiffbi April 22, 2024 11:24
@raphaelm raphaelm changed the title Issue3966 - Datepicker does not respect locale on first load Fix #3966 - Datepicker does not respect locale on first load Apr 23, 2024
@raphaelm
Copy link
Member

Ah, I just see that this makes changes to the upstream library directly. Is that something we want? If we don't expect the library to ever get updated again, we could.

Comment on lines -163 to -166
{% bootstrap_field form.payment_banktransfer_bank_details_sepa_name layout="control" %}
{% bootstrap_field form.payment_banktransfer_bank_details_sepa_iban layout="control" %}
{% bootstrap_field form.payment_banktransfer_bank_details_sepa_bic layout="control" %}
{% bootstrap_field form.payment_banktransfer_bank_details_sepa_bank layout="control" %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this belongs to your other PR, could you try to separate that?

@@ -585,7 +585,7 @@
var monthsView = widget.find('.datepicker-months'),
monthsViewHeader = monthsView.find('th'),
months = monthsView.find('tbody').find('span');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -697,7 +697,7 @@
if (!hasDate()) {
return;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@wiffbi
Copy link
Contributor

wiffbi commented Apr 23, 2024

Well, the library has undergone a major rewrite with version 6 AFAICT. Not sure we upgrade, so I guess it is okay to update the current file to fix bugs (not add features), which might not exist in v6 anymore (who knows). I would add a hint at the top, that the library has local edits though.

Regarding the changes: in my testing it did not work or at least it did not fix, what it says it would (locale being wrong). It fixes the bug that with a min- or max-date given, when you open the datepicker it displays the min-date month, then close it without selecting a date, then reopen it, it will jump to today. With this PR, it stays on the min-date month. It does not fix the locale bug though – in my testing, the locale is not updated when opening the datepicker a second time.

@wiffbi
Copy link
Contributor

wiffbi commented Apr 23, 2024

Not sure why, but this line is commented out, but will set the locale for parsed input-dates (which min/max/viewDate are). Uncommenting this and even maybe moving it to line 963, so it will only set the locale if no custom options.parseInputDate is given.

We might even go so far as to provide our own options.parseInputDate when instatiating the datepicker, so that we do not need to change the library here. I can prepare a PR for that if @raphaelm wants.

Comment on lines +950 to +960
// PROBLEM IS HERE
// WHEN YOU CLICK OUT OF WIDGET WITHOUT SELECTING A DATE, date IS CURRENT DATE
// WHEN YOU SELECT DATE, date STILL JUNE 3 REGARDLESS OF SELECTED DATE
// THEREFORE, we do not want to set date to viewDate when clicking out of widget

// date.month() & viewDate.month() will be the same if date selected by user
// date.month() & viewDate.month() will be different if user clicks out of widget
// therefore, do not set date to be equal to viewDate if date.month() !== viewDate.month()
if (date.month() === viewDate.month()) {
viewDate = date.clone();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT that line does not help at all. And if date.month() === viewDate.month() there is no practical benefit to set the viewdate to a clone of the original date. So I would just remove the line completely:

Suggested change
// PROBLEM IS HERE
// WHEN YOU CLICK OUT OF WIDGET WITHOUT SELECTING A DATE, date IS CURRENT DATE
// WHEN YOU SELECT DATE, date STILL JUNE 3 REGARDLESS OF SELECTED DATE
// THEREFORE, we do not want to set date to viewDate when clicking out of widget
// date.month() & viewDate.month() will be the same if date selected by user
// date.month() & viewDate.month() will be different if user clicks out of widget
// therefore, do not set date to be equal to viewDate if date.month() !== viewDate.month()
if (date.month() === viewDate.month()) {
viewDate = date.clone();
}
// CUSTOM CHANGE: when closing the picker without selecting a date
// this would set the viewDate to basically now() as local var date does
// no respect min- /max-date initially.
// viewDate = date.clone();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants