Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Date input override for simple_form to use calendar_date_select…
… plugin
- Loading branch information
1 parent
32619f6
commit ef28269
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |