I love the simple_form gem for rails but i dont like this line of code:
<%= f.input :deadline, :as => :string, :input_html => { :class
In new formtastic previews answers doesn't work. See http://justinfrench.com/notebook/formtastic-2-preview-custom-inputs Here is a simple working example (save to app/inputs/date_picker_input.rb):
class DatePickerInput < Formtastic::Inputs::StringInput
def input_html_options
{
:class => 'date_picker',
}.merge(super).merge({
:size => '11'
})
end
end
Create a file app/assets/javascripts/date_picker.js with content:
$(function() {
$("input#.date_picker").datepicker();
});
You also need to load jquery-ui. To do so, insert to app/assets/javascripts/application.js line:
//= require jquery-ui
or simply use CDN eg:
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js" %>
Stylesheets for jquery-ui coul be inclded http://babinho.net/2011/10/rails-3-1-jquery-ui/ or from CDN:
<%= stylesheet_link_tag "application", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/themes/ui-lightness/jquery-ui.css" %>