Calendar Date SelectThis is a featured page

Here's a quick guide to getting started with Calendar Date Select gem from Tim Harper, et al.

Dates in forms can suck when using the standard f.date_select. Consider the following:
Model:
class RegistrationSetup
include MongoMapper::Document
key :title, String, :required => true
key :open, Date
key :close, Date
end
And a typical generated view with "date_select:"
View:
<p>
<%= f.label :from %><br />
<%= f.date_select :from %>
</p>

This results in 3 spinners:
Standard date_select
The object save fails unless you deal with the date chunking. In addition the use of 3 spinners can be a bit laborious for the user. Naturally, in the controller, we could reassemble the constituent date parts into a Date... Blech. I'm too lazy for that. Plus I want a more modern date selector!

A pop-up calendar is a better way!

Here's a way that I found to use the calendar_date_select gem (see here)

Step 1. Install:
sudo gem install calendar_date_select

Step 2. Get code from here: http://github.com/timcharper/calendar_date_select/downloads/
  • unzip the download somewhere
  • transfer the appropriate files into your project's directories as follows:
    • public/images
    • public/javascripts
    • public/stylesheets directories
  • put the stylesheets you want (I just copied them all) into
    • public/stylesheets

Step 3. Add to layout/application.html.erb
<%= javascript_include_tag :defaults %>
<%= calendar_date_select_includes %>

Step 4. Add to environment.rb:
config.gem "calendar_date_select"

Step 5. Add to your UI; e.g., _form.html.erb
<div id="calendar">
<p>
<%#= calendar_date_select_tag "e_date", Date.today, :embedded => true, :year_range => 0.years.ago..1.years.from_now %>
Open: <%= f.calendar_date_select :open, :size => 15 %>
Close: <%= f.calendar_date_select :close, :size => 15 %>
</p>
</div>

And voila!
Calendar Date Select popup!

I am sure there are other ways to get this gem installed and working.



JonKern
JonKern
Latest page update: made by JonKern , Sep 7 2010, 11:10 AM EDT (about this update About This Update JonKern Edited by JonKern

9 words deleted

view changes

- complete history)
Keyword tags: calendar javascript rails ruby
More Info: links to this page
There are no threads for this page.  Be the first to start a new thread.

Related Content

  (what's this?Related ContentThanks to keyword tags, links to related pages and threads are added to the bottom of your pages. Up to 15 links are shown, determined by matching tags and by how recently the content was updated; keeping the most current at the top. Share your feedback on Wetpaint Central.)