Skip to content

Rails engine that uses ajax and chronic to parse date text_fields

License

Notifications You must be signed in to change notification settings

biola/chronic_ping

Repository files navigation

chronic_ping

Simple rails engine that uses ajax to ping Chronic, giving users imediate feedback regarding the date they entered in a text field.

Demo

Build Status

Requirements

  • chronic
  • rails > 3.1 using asset pipeline
  • jquery-rails

Usage

In your Gemfile

gem 'chronic_ping'

In your assets/javascript/application.js

//= require chronic_ping

In your form

= f.text_field :due_at, class: 'chronic_ping'

Customize

The following values are already set by default, but if you want to customize them, create a file called config/initializers/chronic_ping.rb that should look something like this:

ChronicPing.configure do |config|
  config.formats = {
    default:        '%B %d, %Y at %I:%M%p',
    datetime:       '%B %d, %Y at %I:%M%p',
    date:           '%B %d, %Y',
    my_new_format:  '...'
  }
end

To use a custom predefined format just specify it in a data-format attribute:

= f.text_field :born_on, class: 'chronic_ping', data: {format: 'date'}

Or you can put a format string directly into the data-format attribute:

= f.text_field :born_on, class: 'chronic_ping', data: {format: '%m/%d/%Y'}

License

This project rocks and uses MIT-LICENSE.

About

Rails engine that uses ajax and chronic to parse date text_fields

Resources

License

Stars

Watchers

Forks

Packages

No packages published