Giter Site home page Giter Site logo

formtastic_calendar's Introduction

FormtasticCalendar

An extension for Formtastic1 to generate lightweight javascript calendar date inputs using the Rails Date Kit2

Example

Where Task#due_date is a :date field

<% semantic_form_for @task do |form| %>
  <% form.inputs do %>
    <%= form.input :due_date, :as => :calendar, :format => '%d %b %Y' %>
  <% end %>
<% end %>

:format is optional as it will default to the local default date format as defined in ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.

Dependencies

You must have the formtastic gem/plugin added to your application.

Required images, javascript and stylesheet can be installed using the generator:

./script/generate formtastic_calendar

Don’t forget to add them to your application layout

<%= stylesheet_link_tag 'calendar' %>
<%= javascript_include_tag 'calendar' %>

Todo

Test, test, test…

Attempt to port this to unobtrusive javascript, and provide graceful degradation if possible.

References

1 Formtastic @ GitHub

2 Rails Date Kit

Copyright © 2009 Paul Smith, released under the MIT license

formtastic_calendar's People

Contributors

elandesign 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

Watchers

 avatar  avatar  avatar

Forkers

timoi

formtastic_calendar's Issues

First day of the week

I am not a java script expert, but is their a place where I can change the first day of the week (currently set to Sunday) to Monday. But this the calandar would start with Monday, not Sunday (very common in europe)
Any help would be appreciated.
Chriss

calendar doesn't work for transient / virtual properties

As there's no way to specify that a transient property should be a 'Date', the calendar plugin should deal with the case when the value is of type String -- currently it crashes even with the use of .try(). Here's my patch for formtastic_calendar.rb:

  def calendar_options(format, value = nil)
    months = '[' + Date::MONTHNAMES[1..12].collect { |m| "'#{m}'" }.join(',') + ']'
    days = '[' + Date::DAYNAMES.collect { |d| "'#{d}'" }.join(',') + ']'

    # BEGIN CHANGE
    value_string = value
    unless value.nil?
      value_string = value.try(:strftime, format) if value.is_a?(Date)
    end

    calendar_options = { :input_html =>
      {
        :onfocus => "this.select();calendar_open(this,{format:'#{format}'," +
          "images_dir:'/images',month_names:#{months},day_names:#{days}})",
        :onclick => "event.cancelBubble=true;this.select();calendar_open("+
          "this,{format:'#{format}',images_dir:'/images',"+
          "month_names:#{months},day_names:#{days}})",
        :value => value_string
        }
      }
     #END CHANGE
  end

undefined input_simple

This looks super helpful and a promising compliment to formtastic.

I'm running into an issue and I'm not sure if it has to do a missing dependency or if something else might be going on.

undefined method input_simple' for #<Formtastic::SemanticFormBuilder:0x0000000ce47f58> /vendor/plugins/formtastic_calendar/lib/formtastic_calendar.rb:12:incalendar_input'

besides the plugin install I have added the Rails Date Kit Helper and the made sure it was referenced in the application controller.

I'll keep looking at this but I was just wondering if I was missing something that might not have been called out in the docs yet or if someone else has encountered this.

Thanks

Calendar does not use validations properly. Throws nil object exception.

The calendar works great and definitely inputs into fields as advertised.

My only problem at the moment is that if you do not input a date field via the calendar, the submitted form throws a nil object exception rather than hitting the validations I've put in and telling you you need to put in a TOIL date.

Is there a way around this or have I missed something I needed to do to hook it up to validations ?

Great work though. Really loving the UX is adds to the app.

thanks,
Daryl.

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.