-
-
Notifications
You must be signed in to change notification settings - Fork 392
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/3574 date field doesnt work when date is entered manually #3724
Fix/3574 date field doesnt work when date is entered manually #3724
Conversation
…is_entered_manually
…is_entered_manually
…is_entered_manually
…is_entered_manually
…is_entered_manually
Hi @decidim/lot-core , I need to know why dates in english don't use the standard |
@tramuntanal what format are they using? |
I think that FormObjects are picking |
@tramuntanal a quick search gives me this:
decidim/decidim-core/config/locales/en.yml Line 731 in c8c316a
|
Hi @decidim/lot-core ,
|
Oh, I misunderstood the problem LOL sorry 😅 For English locales: Maybe it's a typo? Or maybe I did it intentionally (I always thought For the FormObjects: let me check it first, but maybe it's just using a |
FormObjects use irb(main):029:0> I18n.locale
=> :en
irb(main):032:0> Date.parse('09/27/2017')
Traceback (most recent call last):
2: from (irb):32
1: from (irb):32:in `parse'
ArgumentError (invalid date)
irb(main):033:0> Date.parse('27/09/2017')
=> Wed, 27 Sep 2017
irb(main):036:0> Date.parse('2017-09-27')
=> Wed, 27 Sep 2017 Summarizing, as we use Rectify, and thus Virtus, which rely on Date.parse for parsing dates, the best will be to always force the user to enter dates in the 'yyyy-mm-dd' format, or alternatively use a most common and also supported 'dd/mm/yyyy' format. This will affect users entering dates manually whatever is their locale and rendered dates (datepickers will remain the same as now). cc/ @decidim/lot-core @decidim/product @decidim/lot-px any thoughts on this? |
Actually, |
…as it is used also in decidim-verificators, and may be used in any public view.
Hi @decidim/lot-core , (This PR is still WIP) |
@tramuntanal yes, it's OK if you do it in this PR! 😄 |
…is_entered_manually
…is_entered_manually
…is_entered_manually
8ba234f
to
f224407
Compare
I removed some i18n keys that are now unused. That makes me wonder if we should actually keep them. I originally suggested the removal in #3724 (comment), but I'm now not sure about it. Previously, the formatted dates from pickers could be customized to use their own formatting, now they use Thoughts? |
Nah, I think it's fine to leave it as it is. |
@deivid-rodriguez I'll wait for @tramuntanal's opinion and, if he thinks everything looks good, I'll merge this 😄 |
return value unless value.is_a?(String) | ||
Date.strptime(value, I18n.t("date.formats.decidim_short")) | ||
rescue ArgumentError | ||
nil |
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.
Very clever @deivid-rodriguez !
Creating a custom attribute coercer is much better design than overriding coercible.
Just a note, why swallow the ArgumentError
? This will make parsing errors much more difficult to find, I know that they should not happen in production but still when testing they happened to me and was tedious to bind the cause to the specific line.
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.
The situation is described here. Basically, we don't want end users to be able to crash our server at their will, so we need to rescue and swallow. We could keep the nil
return but add some logging in between or even append an error to the attribute, but I think the current version is enough for such an edge case...
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.
OK, I understand now. I did not get that the user would provoke a crash when reading your comment before. Indeed raising an error is not what we want.
@tramuntanal Could you merge latest master to bring this PR up to date? |
…is_entered_manually
I've rescheduled a CI job, it failed due to a random error |
Thank you @mrcasals , this PR is now green! |
@deivid-rodriguez do you mind reviewing the code? 😄 |
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.
It should be the same patch as before, only rebased. Right @tramuntanal? It looks good to me from a quick look, except for the change log.
CHANGELOG.md
Outdated
- **decidim-initiatives**: Only show initiative types fomr the current tenant [\#3887](https://github.com/decidim/decidim/pull/3887) | ||
- **decidim-core**: Allows users with admin access to preview unpublished components [\#4016](https://github.com/decidim/decidim/pull/4016) | ||
- **decidim-proposals**: Rename "votes" column to "supports" when exporting proposals [\#4018](https://github.com/decidim/decidim/pull/4018) | ||
|
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 don't think we've fixed this many things in this PR. Merge problem?
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.
This seems to be a problem with a rebase after we released the 0.14.0 version.
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've just fixed the CHANGELOG @mrcasals
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.
@deivid-rodriguez , yes, I only merged master to solve conflicts.
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.
Ok! I'll merge this as soon as CI passes!
Going in finally! |
👏 🎉 🎉 🎉 |
🎩 What? Why?
Remove the readonly attribute from date fields and add a text help with the localized format to be used by the user to enter the date manually.
📌 Related Issues
📋 Subtasks
CHANGELOG
entry📷 Screenshots (optional)