public
Description: Rails form helpers for dates and times to be entered in text input fields rather than using the standard select lists
Homepage:
Clone URL: git://github.com/adzap/date_time_text_field_helpers.git
100644 123 lines (71 sloc) 3.582 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
= date_time_text_field_helpers
 
Apart from possibly the longest plugin name ever, these are a set of form helpers
that use text fields instead of select dropdowns the standard Rails date form
helpers use. Each date/time component gets its own text field which enables
quicker entry using the keyboard while still using the built in Rails
multi-parameter field handling.
 
Something I like about this plugin (coz I wanted the feature) is that it always
returns the user entered values when a form is redisplayed. This means that if
the user enters garbage or an invalid date (requires date validation with
the validates_timeliness plugin), when form is redisplayed the values
are as the user entered. This is so they can understand what they stuffed up
rather than just blank or a shifted date value which you get when you enter 30th
February and have a date in March returned when using date_select. The shifted
date is particularly dangerous if the user just clicks save again and doesn't
pay attention.
 
 
== Features
 
* Allows easier keyboard entry of dates but with some constraint versus the open
  single text field approach.
 
* Easily add javascript behaviours to enable auto tabbing between fields (see
  javascripts folder in this plugin).
 
* Returns user entered values if form redisplayed due to invalid date to aid
  user correction.
 
* Harnesses the power of Ruby on Rails to maximize your potential to be the
  person you really want to be.
 
 
== Usage
 
So instead of:
  
  date_select :person, :date_of_birth
  
  or
  
  time_select :person, :time_of_birth
  
  or
  
  datetime_select :person, :date_and_time_of_birth
 
use:
  
  date_text_field :person, :date_of_birth
  
  or
  
  time_text_field :person, :time_of_birth
  
  or
  
  datetime_text_field :person, :date_and_time_of_birth
 
 
== Example
 
The helper return the date parts as text fields i.e.
 
  date_text_field :person, :date_of_birth, :order => [:day, :month, :year], :blank => true
  
returns this for a new person record
 
  <span id="person_date_of_birth" class="date_time_field">
    <input id="person_date_of_birth_3i" class="day_field" type="text" value="" size="1" name="person[date_of_birth(3i)]"/>
    -
    <input id="person_date_of_birth_2i" class="month_field" type="text" value="" size="1" name="person[date_of_birth(2i)]"/>
    -
    <input id="person_date_of_birth_1i" class="year_field" type="text" value="" size="3" name="person[date_of_birth(1i)]"/>
  </span>
 
 
== Options
 
Most of the options which can be used with the standard Rails date helpers apply
including :order, :default, :include_seconds and so on.
 
A few new options are:
 
  :date_separator - Sets the character displayed between the date components
                    
  :time_separator - guess
  
  :date_time_separator - the separator between the date and the time parts
                
  :blank - acts like :include_blank option to use blank fields rather than the
           default current date/time if the column has no value yet.
 
 
== Resources
 
* javascripts/date_time_field_autotab.js
    copy over to your apps javascripts folder or copy/paste into application.js
 
 
== Info
 
Site for the plugin is just the googlecode site
  http://github.com/adzap/date_time_text_field_helpers/
 
 
== Test/Specs
 
Only Rspec specs are included and can be run standalone outside a rails app
 
  rake spec
 
 
== Credits
 
* It is mostly adapted from the Rails source so props to DHH et al.
* Adam Meehan (adam.meehan at gmail.com)
  
== Copyright/License
 
Copyright (c) 2008 Adam Meehan, released under the MIT license