开发者

Date select : default year selected

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜