class DatepickerInput

Based on: stackoverflow.com/questions/5007785/how-do-i-write-a-cleaner-date-picker-input-for-simpleform

Works well with JQueryUI’s datepicker and I18n.

Public Instance Methods

input() click to toggle source

Builds the input text field and an hidden field with class attribute_name-alt

# File lib/simple-form-datepicker.rb, line 32
def input
  @builder.text_field(attribute_name, input_html_options) + \
  @builder.hidden_field(attribute_name, value: input_html_options[:value], class: attribute_name.to_s + "-alt")
end
input_html_classes() click to toggle source

Adds the “datepicker” class to the input element

Calls superclass method
# File lib/simple-form-datepicker.rb, line 27
def input_html_classes
  super.push('datepicker')
end
input_html_options() click to toggle source

Builds options for the dateicker input, sets it’s value using Rails’s date format and adds behaviour: ‘datepicker’ to its date-atrributes.

Calls superclass method
# File lib/simple-form-datepicker.rb, line 16
def input_html_options
  value = object.send(attribute_name)
  options = {
    value: value.nil? ? nil : value.strftime("%Y-%m-%d"),
    data: { behaviour: 'datepicker' }  # for example
  }
  # add all html option you need...
  super.merge options
end