Class: BbDatePickerInput
- Inherits:
-
SimpleForm::Inputs::Base
- Object
- SimpleForm::Inputs::Base
- BbDatePickerInput
- Defined in:
- lib/bb_date_picker_input.rb
Overview
Create an input-text-field with a date-time-picker widget attached. Also makes sure the given date-time-value is being put in the correct format.
Instance Method Summary collapse
-
#input(_wrapper_options) ⇒ Object
The method that should return the widgets HTML based on the sat arguments.
Instance Method Details
#input(_wrapper_options) ⇒ Object
The method that should return the widgets HTML based on the sat arguments.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bb_date_picker_input.rb', line 6 def input() # Parse the value. if [:value] date = [:value] elsif @builder.object.present? date = @builder.object.send(attribute_name) else date = nil end if date.present? val = date.strftime("%Y-%m-%d") year = date.year month = date.month day = date.day end # Parse classes. classes = ["form-control"] class_arg = [:class] if class_arg if class_arg.is_a?(Array) classes += class_arg else classes << class_arg end end # Generate and return HTML for the widget. content_tag = template.content_tag(:div, class: "bb-date-picker") do html = "" html << @builder.hidden_field("#{attribute_name}(1i)", value: year, class: "bb-date-picker-input-year") html << @builder.hidden_field("#{attribute_name}(2i)", value: month, class: "bb-date-picker-input-month") html << @builder.hidden_field("#{attribute_name}(3i)", value: day, class: "bb-date-picker-input-day") html << template.text_field_tag("", val, class: classes, data: {date_format: "yyyy-mm-dd", provide: "datepicker"}) html.html_safe # rubocop:disable Rails/OutputSafety end content_tag end |