Class: DatepickerInput
- Inherits:
-
SimpleForm::Inputs::StringInput
- Object
- SimpleForm::Inputs::StringInput
- DatepickerInput
- 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
-
#input ⇒ Object
Builds the input text field and an hidden field with class attribute_name-alt.
-
#input_html_classes ⇒ Object
Adds the “datepicker” class to the input element.
-
#input_html_options ⇒ Object
Builds options for the dateicker input, sets it’s value using Rails’s date format and adds behaviour: ‘datepicker’ to its date-atrributes.
Instance Method Details
#input ⇒ Object
Builds the input text field and an hidden field with class attribute_name-alt
32 33 34 35 |
# File 'lib/simple-form-datepicker.rb', line 32 def input @builder.text_field(attribute_name, ) + \ @builder.hidden_field(attribute_name, value: [:value], class: attribute_name.to_s + "-alt") end |
#input_html_classes ⇒ Object
Adds the “datepicker” class to the input element
27 28 29 |
# File 'lib/simple-form-datepicker.rb', line 27 def input_html_classes super.push('datepicker') end |
#input_html_options ⇒ Object
Builds options for the dateicker input, sets it’s value using Rails’s date format and adds behaviour: ‘datepicker’ to its date-atrributes.
16 17 18 19 20 21 22 23 24 |
# File 'lib/simple-form-datepicker.rb', line 16 def value = object.send(attribute_name) = { value: value.nil? ? nil : value.strftime("%Y-%m-%d"), data: { behaviour: 'datepicker' } # for example } # add all html option you need... super.merge end |