adzap / date_time_text_field_helpers

Rails form helpers for dates and times to be entered in text input fields rather than using the standard select lists

This URL has Read+Write access

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