adzap/date_time_text_field_helpers
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
= 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