Class: DatepickerInput

Inherits:
SimpleForm::Inputs::StringInput
  • Object
show all
Defined in:
lib/simple-form-datepicker.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#inputObject



28
29
30
31
# File 'lib/simple-form-datepicker.rb', line 28

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_classesObject



24
25
26
# File 'lib/simple-form-datepicker.rb', line 24

def input_html_classes
  super.push('datepicker')
end

#input_html_optionsObject



14
15
16
17
18
19
20
21
22
# File 'lib/simple-form-datepicker.rb', line 14

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