Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the default value for date_field in rails 4

I have a few forms in my application which where using date_select and I've just changed to using date_field (which uses the HTML5 form elements) the only issue I'm having is that date_select would default to todays date which was perfect for us but date_field is defaulting to dd/mm/yyyy instead.

I'm running into issues with people blindly submitting the form and triggering validation errors.

Is it possible to default date_field to today?

like image 561
Arcath Avatar asked Sep 18 '13 08:09

Arcath


1 Answers

If you installed Rails4 via gem, it has below bug yet.

https://github.com/rails/rails/commits/master/actionview/lib/action_view/helpers/tags/datetime_field.rb

Fix above and you can set default value like this

<%= f.date_field :birthday, :value => Time.now.strftime('%Y-%m-%d') %>
like image 158
azihsoyn Avatar answered Sep 17 '22 15:09

azihsoyn