2

Add :day_format option to date_select by shunichi · Pull Request #43567 · rails/...

 2 years ago
source link: https://github.com/rails/rails/pull/43567
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Copy link

Contributor

shunichi commented on Oct 29

Summary

Added :day_format option to date_select like :year_format option.

In Rails application with ja locale (ja means Japanese locale) and rails-i18n gem, date_select shows following:

In Japanese culture, date 2021-10-29 is usually written like 2021年10月29日. 年 means year, 月 means month, and 日 means day.

But date_select have no option to customize day format. So I added :day_format option.

With the option,

form.date_select :published_date, year_format: ->(year) { "#{year}年" }, day_format: ->(day) { "#{day}日" }

this code produces following output:

The option can be used to produce following output:

form.date_select :published_date, order: %i[day month year], day_format: ->(day) { day.ordinalize }

Other Information

No other information


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK