-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Datepicker don't show selected date properly #982
Comments
RailsAdmin chokes on 'es.date.formats.long' => '%d de %B de %Y' Maybe it's the repetition of 'de' that cause the parsing failure. You should change the key until it gets fixed. |
That's right, change the key 'es.date.formats.long' from '%d de %B de %Y' to '%d %B %Y' and now works fine. |
The problem is with this function in 'lib/rails_admin/config/fields/type/datetime.rb': # Ruby to javascript formatting options translator
def js_date_format
# Ruby format options as a key and javascript format options
# as a value
translations = {
"%a" => "D", # The abbreviated weekday name ("Sun")
"%A" => "DD", # The full weekday name ("Sunday")
"%b" => "M", # The abbreviated month name ("Jan")
"%B" => "MM", # The full month name ("January")
"%d" => "dd", # Day of the month (01..31)
"%D" => "mm/dd/y", # American date format mm/dd/yy
"%e" => "d", # Day of the month (1..31)
"%F" => "yy-mm-dd", # ISO 8601 date format
# "%H" => "??", # Hour of the day, 24-hour clock (00..23)
# "%I" => "??", # Hour of the day, 12-hour clock (01..12)
"%m" => "mm", # Month of the year (01..12)
"%-m" => "m", # Month of the year (1..12)
# "%M" => "??", # Minute of the hour (00..59)
# "%p" => "??", # Meridian indicator ("AM" or "PM")
# "%S" => "??", # Second of the minute (00..60)
"%Y" => "yy", # Year with century
"%y" => "y", # Year without a century (00..99)
}
localized_date_format.gsub(/%\w/) {|match| translations[match]}
end So with the :es locale, and the long format ('%d de %B de %Y'), this '"%e" => "d"' replace the 'd' in 'de' with the day selected. I can't think now how to fix this, but a better solution than change the long format (maybe you are using it in other places), it could be configure rails admin field to use another format, :default or another custom added in locale files: For all views configure :date_field_name, :date do
date_format :default
end Or only in the edit views field :date_field_name do
date_format :default
end You can use 'strftime_format "%d/%m/%Y"' too, but I think it's better to set this format in locale files. Thanks for this awesome engine 😃 |
This happens with pt-br locale too, and rsierra fix resolves it as well. |
I can report that problem too |
Same here, with spanish. I fixed by adding the following lines at the end of
(Note that there are two spaces before |
Closed by #2451. |
I have the same issue with French translation. I'd try the method of dcabo, but it didn't match as I configured all the application with I18n-fr... |
I try to change, but it doesn't match :
|
Ok, now it matches. But there is no hours in no hours anyway, just because of the function in 'lib/rails_admin/config/fields/type/datetime.rb' ? It is not possible to change this file ? |
I found a solution, for my views as I use a calendar which need the hours, I have added in my locales/fr.yml for the translalation
And I can use use 'my_field.hour, format: :very_long' to get the date ans the hour |
I have a better recommendation... with my code before, updating an object with an hour always put it back to midnight 00:00. But I found how to resolve it...
in my rails_admin.yml :
and now it seems to be all right, I can edit without breaking the datetime, and change it also in rails_admin... |
I want to point out that this may apply to other locales too. This is because rails-i18n gem which you may use may specify the long format as Update: another solution in this PR https://github.com/sferik/rails_admin/pull/2788/files |
In the form of a new object that have a field datetime, the datepicker for complete the field don't show selected date properly.
Ex: if I choose 15/02/2012 in spanish, the field show '15 15e febrero 15e 2012' instead of '15 de febrero de 2012'
When save the object for this example, the persisted value in the database is '15/02/2015' instead of '15/02/2012'
The text was updated successfully, but these errors were encountered: