Skip to content

Instantly share code, notes, and snippets.

@dimroc
Created January 29, 2015 21:41
Show Gist options
  • Select an option

  • Save dimroc/d169bed0afae7b7d9610 to your computer and use it in GitHub Desktop.

Select an option

Save dimroc/d169bed0afae7b7d9610 to your computer and use it in GitHub Desktop.
# Could not call this DatepickerInput because it leads to
# the setting of css classes that cause chaos in the javascript/css
# side of things.
class BetterDateInput < SimpleForm::Inputs::StringInput
def input(wrapper_options = nil)
input_html_classes.unshift(:datepicker)
input_html_options[:autocomplete] = 'off'
value = @builder.object.send(attribute_name)
input_html_options[:value] = case value
when Date, Time, DateTime
format = options[:format] || :calendar
l(value, format: format)
else
value.to_s
end
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
@builder.text_field(attribute_name, merged_input_options)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment