Class: SimpleForm::Bootstrap::Inputs::DateTimeInput
- Inherits:
-
Inputs::Base
- Object
- Inputs::Base
- SimpleForm::Bootstrap::Inputs::DateTimeInput
- Defined in:
- lib/simple_form/bootstrap/inputs/date_time_input.rb
Overview
Inspired by this StackOverflow answer: stackoverflow.com/a/19018501 I have modified this to work with dates AND times, and also to work better with browsers with JavaScript disabled.
Instance Method Summary collapse
Instance Method Details
#input(_ = nil) ⇒ Object
5 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 |
# File 'lib/simple_form/bootstrap/inputs/date_time_input.rb', line 5 def input(_ = nil) = .with_indifferent_access format = .delete(:format) || default_format # Integrate with Bootstrap's styling [:class] << 'form-control' = .deep_dup [:class] << 'bootstrap-datepicker' [:class] << 'bootstrap-timepicker' if input_type == :bootstrap_date_time [:id] = "#{attribute_name}_hidden" [:value] ||= format_date(value(object), format) [:data] = { 'date-format' => strftime_to_momentjs_format(format) } hidden_field_group_classes = [:class].dup hidden_field_group_classes.delete('form-control') [:value] ||= value(object).try(:to_s) return_string = <<-END_INPUT <div class="input-group #{hidden_field_group_classes.join(' ')}" style="display: none"> #{@builder.hidden_field(attribute_name, .to_hash)} <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span> </div> #{@builder.text_field(attribute_name, .to_hash)} END_INPUT return_string.html_safe end |