How to use a text_field for dates?

Hello,

I need to accept dates in a form using a text_field and not a
date_select. Why? Well, because for users it’s faster to type a date.

But if I enter a simple date like “13/05/2012” (dd/mm/yyyy format), when
I want to edit this register, in the text_field appears “2012-05-13”.

How can I change this behavior, so in the text_field appears
“13/05/2012”?

Thank you!

Hello,

You might want to check out this

:order - Set to an array containing :day, :month and :year to customize
the
order in which the select fields are shown. If you leave out any of the
symbols, the respective select will not be shown (like when you set
:discard_xxx
=> true. Defaults to the order defined in the respective locale (e.g.
[:year, :month, :day] in the en locale that ships with
Railshttp://api.rubyonrails.org/classes/Rails.html)

:date_separator - Specifies a string to separate the date fields.
Default
is “” (i.e. nothing).

Best regards

And this: Datepicker | jQuery UI

Hi Marc,

How can I change this behavior, so in the text_field appears
“13/05/2012”?

Thank you!

You can use the #strftime method to easily accomplish what you want.

ruby-1.9.2-p290 :001 > require ‘date’
=> true
ruby-1.9.2-p290 :002 > d = Date.parse(‘2012-05-13’)
=> #<Date: 2012-05-13 (4912121/2,0,2299161)>
ruby-1.9.2-p290 :003 > d.strftime(’%d/%m/%Y’)
=> “13/05/2012”

HTH,
Bill