Coder Social home page Coder Social logo

ui_datepicker-rails3's Introduction

jQuery UI Datepicker for Rails 3.x

This gem adds support for jQuery UI Date and DateTime picker for Rails 3.x form builders, including:

  • Formtastic 2.x+
  • SimpleForm
  • ActiveAdmin 0.4+

Feel free to provide patches/extensions to support other form builders.

Install

Insert into Gemfile:

gem 'ui_datepicker-rails3'

Activate it like this:

UiDatePickerRails3.activate :simple_form

This can be done fx from inside an initializer. You can pass either :simple_form, :formtastic or :active_admin to the #activate method.

jQuery UI Configuration

For basic Rails form builder support, please see "jquery_datepicker"

In Gemfile, insert:

gem 'jquery-rails'

Then install jquery with UI, by executing the following command from console:

rails generate jquery:install --ui

In Rails 3.1 when using the asset pipeline, this generator is deprecated, so you’ll need to add a line to your app/assets/javascripts/application.js file:

//= require jquery-ui

Formtastic

This gem requires Formtastic 2.0+.

Note: For a version that supports Formtastic < 2.0, see [formtastic_datepicker]:(https://github.com/kristianmandrup/formtastic_datepicker)

ActiveAdmin

The ActiveAdmin extension should work with ActiveAdmin 0.4+ (Formtastic >= 2.0)

Formtastic (by justinfrench)

The gem adds a couple of new form inputs to Formtastic that can be used like this:

<% semantic_form_for @person do |f| -%>
  <% f.inputs do -%>
    <%= f.input :name %>
    <%= f.input :born, :as => :ui_date_picker %>
  <% end -%>
  <%= f.buttons %>
<% end -%>

The Formtastic Input class adds class='ui-date-picker' to the text input, which can the be matched by jQuery and converted to the date picker widget.

<% semantic_form_for @person do |f| -%>
  <% f.inputs do -%>
    <%= f.input :name %>
    <%= f.input :born, :as => :ui_date_time_picker %>
  <% end -%>
  <%= f.buttons %>
<% end -%>

The Formtastic Input class adds class='ui-datetime-picker' to the text input, which can the be matched by jQuery and converted to the date-time picker widget.

SimpleForm (by plataformatec)

The gem adds a couple of new form inputs to SimpleForm that can be used like this:

<% simple_form_for @person do |f| -%>
  <%= f.input :name %>
  <%= f.input :born, :as => :ui_date_picker %>
<% end -%>

The SimpleForm Input class adds class='ui-date-picker' to the text input, which can the be matched by jQuery and converted to the date picker widget.

<% simple_form_for @person do |f| -%>
  <%= f.input :name %>
  <%= f.input :born, :as => :ui_date_time_picker %>
<% end -%>

The SimpleForm Input class adds class='ui-datetime-picker' to the text input, which can the be matched by jQuery and converted to the date-time picker widget.

Configuration

These configuration tips are only appropriate for a static datepicker, i.e one with a fixed set of options and a given language. Handling a more dynamic configuration is left as an exercise.

When the gem has been installed the datepicker should be configured as follows

Install the jquery-ui CSS. You can get a bundle to match your site from ThemeRoller. From your theme bundle, extract the CSS directory and place it somewhere under app/assets/stylesheets/.

Activate datepicker on all matching input elements in one of your javascript (or coffee script) files, fx datepicker.js or datepicker.js.coffee.

$(document).ready(function(){
  $('input.ui-date-picker').datepicker();
  $('input.ui-datetime-picker').datetimepicker();
});

The same in coffescript:

$ ->
  $('input.ui-date-picker').datepicker()
  $('input.ui-datetime-picker').datetimepicker()

You can even include an premade script included as ui_datepicker.js (which executes the above code), or customize the initialization to fit your needs: Using the asset pipeline, simply add:

//= require ui_datepicker

Localization (optional)

To add localization, you can additionally add localization options to the datepicker() call.

Example: Using the swedish localization:

$(document).ready(function(){
  $('input.ui-date-picker').datepicker('option', 'sv' );
});

The same in coffescript:

$ ->
  $('input.ui-date-picker').datepicker('option', 'sv')

For any other language exchange the local 'sv' to the appropriate (localized) country code.

Copy the appropriate localization file from "jQuery-UI i18n" to your js asset folder, fx at: app/assets/javascripts/i18n/jquery.ui.datepicker-sv.js

Then make sure a reference to the locale file is added in the manifest file.

//= require i18n/jquery.ui.datepicker-sv to your js manifest file.

You can also use the included datepicker locale files as a base (see vendor/assets of this gem). This gem includes a helper method #ui_localizers that can be used like this (fx in your Rails layout file or similar):

<%= javascript_include_tag UiDatePickerRails3.ui_localizers :ar, :ca, :da %>

It will generate strings of the form "ui/i18n/jquery.ui.datepicker-#{country_code}"

Styling (optional)

Style the datepicker by adding a datepicker.css file to your css assets.

You can use the Themeroller (http://jqueryui.com/themeroller/) to define and download an appropriate css file and the pictures needed. Add the downloaded Themeroller css file to the css assets and add the Themeroller images to the image assets. Edit the datepicker css and change all image references by removing all the "images/" prefixes e.g from url(images/ui-icons_222222_256x240.png) to url(ui-icons_222222_256x240.png)

Note: It is also possible to load only the js needed for the datepicker widget by using the js files that are downloaded from Themeroller.

A 'smoothness' theme is included with this gem. Simply add to application.css:

/*
 *= require ui/smoothness/jquery-ui-theme
*/

Advanced configuration

Add any additional datepicker options as defined in the "Datepicker" docs.

Example: add option for displaying week number and displaying a drop-down of months:

$(document).ready(function(){
  var datepicker_widgets = $('input.ui-date-picker');

  datepicker_widgets.datepicker( 'option', 'showWeek', true);
  datepicker_widgets.datepicker( 'option', 'changeMonth', true );
});

ActiveAdmin integration

In the Gemfile add this gem after ActiveAdmin (gem 'active_admin') to make sure it loads after and overrides/extends ActiveAdmin appropriately.

gem 'active_admin'
gem 'ui_datepicker-rails3'

Note: To configure css and js files with ActiveAdmin you can use the config DSL in the ActiveAdmin initializer.

ui_datepicker-rails3's People

Contributors

crmaxx avatar gudata avatar jjohnson-xx avatar kristianmandrup avatar zhmurko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ui_datepicker-rails3's Issues

Keep getting UnknownInputError (Formtastic 2.1)

Hi there, I've been trying to find an optimal solution for a datetime picker in Formtastic, and your gem seemed to fit the bill well. However, I'm having some trouble configuring my application to work with it. I'm hoping this is the right place to ask for help?

For starters, I'm running Rails 3.1.1, Ruby 1.9.2, Formtastic 2.1.1.

The problem I'm getting is that in my view (partial _fields.html.erb, I have this:

<%= f.input :deadline_date, :as => :ui_date_picker %>

where :deadline_date is a :datetime field. But everytime I browse to that page, I get the following error:

Formtastic::UnknownInputError

I followed all the instructions, my application.js looks like this:

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .

and I have a file in /config/initializations/ui_date_picker_rails3.rb that looks like this (I even put in that 'puts' to make sure it gets included, and it does):

UiDatePickerRails3.activate :formtastic
puts "UIDatePickerRails3 included"

I dont' have ActiveAdmin installed (not using it).

I can't for the life of me figure out what I did wrong. Any help would be appreciated, thanks!

UiDatePickerInput for ActiveAdmin doesn't localized values

I'm using AA and when I edit an entity which has a date attribute, it's not localized.

I had to add this:

module ActiveAdmin
  module Inputs
    class UiDatePickerInput < ::ActiveAdmin::Inputs::DatepickerInput
      def input_html_options
        options = super
        options[:class] = [options[:class], "ui-date-picker"].compact.join(' ')
        options[:value] = localized(value) 
        options
      end

      def localized value
        value.nil? ? nil : I18n.localize(object.send(method))
      end  

      def value
        input_options[:value] || object.send(method).try(:strftime, format)
      end

      def format
        input_options[:format] || '%d %b %Y'
      end
    end
  end
end

in an initializer to make it work

Not hosted on rubygems?

gem 'ui_datepicker-rails3'

Doesn't work (since it's not hosted on rubygems?)

gem 'ui_datepicker-rails3', :git => 'git://github.com/kristianmandrup/ui_datepicker-rails3.git'

would be correct.

:ui_date_time_picker

no display hours

my code:
f.input :start_date, as => :ui_date_time_picker, :input_html => { :class => 'ui-datetime-picker', :size => 20 }

used activeadmin

SimpleForm: custom values/formats do not work

I've tried outputting a custom date format by using strftime as demonstrated below, using :order => [:month, :day, :year], and one or two other random solutions found around the internet.

= f.input :date, as: :ui_date_picker, input_html: { value: @event.date.strftime("%m/%d/%Y") }

But no matter what format or output I try I always get the horrible YYYY-mm-dd format. Is there something I'm missing (options) or is this a bug in the gem?

Formtastic "Unable to find input class"

Hi guys... I have a problem with this gem.

I'm using the Formtastic v2.2.1, but when i add ":as => :ui_date_picker" in my input, i will received this error:

"Unable to find input class for ui_date_picker"

My code:

= f.input :data_de_nascimento,
:wrapper_html => { :class => 'fl right' },
:as => :ui_date_picker

My formtastic.rb initializer:

UiDatePickerRails3.activate :formtastic

PS: Sorry my poor English. =)

Unsupported Form builder or framework: active_admin - uninitialized constant ActiveAdmin::Inputs::DatepickerInput (NotImplementedError)

I'm getting the following error startup up my rails server using ui_datepicker-rails3 1.0.0 and active_admin 0.3.4.

c:/Ruby187/lib/ruby/gems/1.8/gems/ui_datepicker-rails3-1.0.0/lib/ui_datepicker-rails3.rb:18:in `load_extension': Unsupported 
Form builder or framework: active_admin - uninitialized constant ActiveAdmin::Inputs::DatepickerInput (NotImplementedError)
        from c:/Ruby187/lib/ruby/gems/1.8/gems/ui_datepicker-rails3-1.0.0/lib/ui_datepicker-rails3.rb:12:in `activate_one'
        from c:/Ruby187/lib/ruby/gems/1.8/gems/ui_datepicker-rails3-1.0.0/lib/ui_datepicker-rails3.rb:7:in `activate'
        from c:/Ruby187/lib/ruby/gems/1.8/gems/ui_datepicker-rails3-1.0.0/lib/ui_datepicker-rails3.rb:7:in `each'
        from c:/Ruby187/lib/ruby/gems/1.8/gems/ui_datepicker-rails3-1.0.0/lib/ui_datepicker-rails3.rb:7:in `activate'

My gemfile:

source 'http://rubygems.org'
gem 'rails', '3.0.3'
group :production do
  gem 'rack', '1.2.1'
end
gem 'mysql'
gem 'activeadmin'
gem 'ui_datepicker-rails3'

I have this at the bottom of my config/initializers/active_admin.rb:

UiDatePickerRails3.activate :active_admin

I've looked, and ActiveAdmin::Inputs::DatepickerInput is the correct module...can you shed some light on this issue?

Thanks,
Ryan

date_time_picker not working

Hello,

i have setup ui_datepicker-rails3 with simple_form. ui_date_picker is working fine, ui_date_time_picker opens only a calendar without time.

<%= f.input :start_at, :as => :ui_date_picker %>
<%= f.input :end_at, :as => :ui_date_time_picker %>

Can somebody help?

localization returns an error

Formtastic::Inputs::UiDatePickerInput#input_html_options

has a line

super.update(:class => new_class, :value => localized(value))

which fails because value returns a formatted string so I18n.localize(value) throws an exception.

Should it be something like this?

  super.update(:class => new_class, :value => localized(object.send(method)))

ui-datpicker-rails3 fails in production

I have used the new ui-datepicker-rails3 successfully when developing an application locally on a Mac 10.6.8
However, when I transform the application to a server hotel to be run in production mode, I have problem
The server hotel cannot get the ui-datepicker-rails3 gem to work correctly. The have used bundle install and update a couple of times but It seems as they cannoit check it out
Any idees !!!!!!!!!
Here is the gem in the Gem file:
gem 'ui_datepicker-rails3',:git => 'git://github.com/kristianmandrup/ui_datepicker-rails3'
In the local development i first tried
gem 'ui_datepicker-rails3', but it doesnt work so I added :git => 'git://github.com/kristianmandrup/ui_datepicker-rails3'

Here is the first part of the log
[ pid=12034 thr=4801320 file=utils.rb:176 time=2012-03-14 22:38:59.786 ]: *** Exception PhusionPassenger::UnknownError in PhusionPassenger::Rack::ApplicationSpawner (git://github.com/kristianmandrup/ui_datepicker-rails3 (at master) is not checked out. Please run bundle install (Bundler::GitError)) (process 12034, thread #Thread:0x00000000928650):
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/source.rb:572:in rescue in load_spec_files' from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/source.rb:570:inload_spec_files'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/source.rb:385:in local_specs' from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/source.rb:555:inspecs'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/definition.rb:147:in block in resolve' from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/definition.rb:145:ineach'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/definition.rb:145:in resolve' from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/definition.rb:90:inspecs'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/definition.rb:135:in specs_for' from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/definition.rb:124:inrequested_specs'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/environment.rb:23:in requested_specs' from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:11:insetup'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:110:in setup' from /var/lib/passenger-standalone/3.0.11-x86_64-ruby1.9.2-linux-gcc4.4.3-1002/support/lib/phusion_passenger/utils.rb:326:inprepare_app_process'
from /var/lib/passenger-standalone/3.0.11-x86_64-ruby1.9.2-linux-gcc4.4.3-1002/support/lib/phusion_passenger/rack/application_spawner.rb:156:in `block in initialize_server'

Rails 3.2.1

Where should be placed or executed this line to enable the simple_form to rails 3.2.1?

  • UiDatePickerRails3.activate :simple_form

[]'s

Stclara

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.