Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting a date input using simple_form

I have a date type field in my database.

Here's the view code I'm using:

# Using 'as: :string' to avoid those three dropdowns rails generates.
= f.input_field :start_date, as: :string, class: 'form-control datepicker'

When saving a date I use a jquery plugin that shows a calendar and writes in a date like: 11/05/2013.

But when editing the same record, the input is populated with a value 2013-05-11.

How can I make it so simple_form actually respects my date format defined in en.yml?

like image 521
sergserg Avatar asked Nov 04 '13 03:11

sergserg


Video Answer


1 Answers

Here's what you need :

f.input :my_date,
        :as => :string, 
        :input_html => { :value => localize(f.object.my_date) }

PS : This was the first link in google search :)

like image 186
rb512 Avatar answered Oct 14 '22 21:10

rb512