GithubHelp home page GithubHelp logo

jer0m / date_time_text_field_helpers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adzap/date_time_text_field_helpers

2.0 2.0 1.0 120 KB

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

License: MIT License

Ruby 93.36% JavaScript 6.64%

date_time_text_field_helpers's Introduction

= 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

date_time_text_field_helpers's People

Contributors

adzap avatar eric1234 avatar jer0m avatar johnmcaliley avatar map7 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.