views:

22

answers:

1

On form 1, I have a formtastic date_select field.

= f.input :date_from, :discard_day   => true, 
                      :discard_month => true,
                      :order         => [:year], 
                      :start_year    => 1950, 
                      :end_year      => Date.today.year, 
                      :include_blank => false

When the form is rendered, the year drop down box defaults to 1950.

On form 2, I have another formtastic date_select field.

= f.input :date_from, :discard_day   => true, 
                      :order         => [:month, :year], 
                      :start_year    => 1950, 
                      :end_year      => Date.today.year, 
                      :include_blank => false

When the form is rendered, the year drop down box defaults to 2000.

How do you explain this behavior? Ideally, I want the year field to default to 10 years ago.

P.S: Setting default value made no difference.

:default       => Date.today
+1  A: 

Have you tried:

:selected => Date.today.year - 10

Looking at the RDoc for formtastic, that should work: http://rdoc.info/github/justinfrench/formtastic/master/Formtastic/SemanticFormBuilder:date_input

Sidane
Thanks, that worked.
KandadaBoggu