RubyGems Navigation menu

bjeanes-livedate 1.1.0

Livedate

A simple Rack middleware that parses a dates using Chronic, and returns the result in a standardized manner. The idea is to use this to verify the input in date input fields using AJAX, to provide immediate feedback to the user.

Usage

Include Livedate in your middleware stack. In Rails, this is done in environment.rb

config.gem 'livedate'
config.middleware.use "Livedate"

Specify the desired date + datetime formats you want too. Default error message for strings that Chronic can’t pass can also be provided. The defaults are:

config.middleware.use "Livedate", 
  :date_format => '%Y-%m-%d',
  :datetime_format => ''%Y-%m-%d %H:%M',
  :invalid_format => ''

This will catch requests to /parsedate. Use GET requests and provide a parameter ‘date’ or ‘datetime’. The value will be parsed by Chronic and returned formatted as 2009-01-01 or 2009-01-01 12:45, depending on the parameter name.

Scripts

There are two generators available to get simple javascripts that use livedate. Both will replace the contents on input elements with classes .date or .datetime on change with the result from the Chronic parse.

script/generate livedate_jquery
script/generate livedate_prototype

Will put the appropriate version of the script in your public/javascripts directory. Feel free to change these if you need a different behavior.

Gemfile:
= Copy to clipboard Copied!

install:
=

Versions:

  1. 1.1.0 - May 25, 2011 (6 KB)
  2. 1.0.0 - August 11, 2014 (6 KB)

Runtime Dependencies (1):

chronic >= 0.2.3

Owners:

Authors:

  • Erik Hansson

SHA 256 checksum:

8aea5074c78cdd8eb3a02e52374fe4f3a7afdaaee429de7941fad108ff11c235

Total downloads 8,580

For this version 5,677

Licenses:

N/A

Required Ruby Version: >= 1.8

Links: