开发者

Rails date_select as single pulldown instead of three?

The current date_select form helper in Rails creates three pulldown menus for selecting month, date, and year f开发者_StackOverflow中文版or a date. Is there away to instead have a single pulldown with a list of dates?

For example, a list of the next 30 days from "Jan 1, 2011" to "Jan 30, 2011"?


While not a select/pulldown control, an alternative option is the jQuery datepicker. Using that, you could do this:

Your date field:

<%= f.text_field :some_date %> # => presume that element id is some_date_id

You can add a drop down calendar to it like this:

<script type="text/javascript">
  $(function() {
    $( "#some_date_id" ).datepicker();
  });
</script>


Instead of writing a date_select_tag use a select_tag and provide it an array of dates.

select_tag "invoice_date", options_from_collection_for_select(@array_of_dates,:first,:first)

Not sure how you're using the form. Perhaps if you post that snippet, a more specific and correct answer can be provided.

If you need date_select to work differently, you need to override the helper and roll your own. If you just want a certain functionality in your app and not interested in changing Rails itself, go for the select_tag option.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜