Skip to content

Commit

Permalink
Added Date input override for simple_form to use calendar_date_select…
Browse files Browse the repository at this point in the history
… plugin
  • Loading branch information
ndbroadbent committed Nov 16, 2011
1 parent 32619f6 commit ef28269
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/inputs/date_time_input.rb
@@ -0,0 +1,38 @@
class DateTimeInput < SimpleForm::Inputs::DateTimeInput
include ActionView::Helpers::TagHelper
include ActionView::Helpers::JavaScriptHelper

def input
add_autocomplete!
field = @builder.text_field(
attribute_name,
input_html_options.merge(datetime_options(object.send(attribute_name)))
)
element_id = field[/id="([a-z0-9_]*)"/, 1]
field << javascript_tag(%Q{crm.date_select_popup('#{element_id}', false, #{!!(input_type =~ /time/)});})
end

def label_target
attribute_name
end

private

def datetime_options(value = nil)
return {} if value.nil?
params = if input_type =~ /time/
[value.localtime, {:format => :mmddyyyy_hhmm}]
else
[value.to_date, {:format => :mmddyyy}]
end
{ :value => I18n.localize(*params).html_safe }
end

def has_required?
options[:required]
end

def add_autocomplete!
input_html_options[:autocomplete] ||= 'off'
end
end

0 comments on commit ef28269

Please sign in to comment.