Sha256: b17edc0f581d64711d6b4cb906f8a8db930b7275613e8fc5f789c71381b5b5f4

Contents?: true

Size: 1.16 KB

Versions: 8

Compression:

Stored size: 1.16 KB

Contents

class DateTimePickerInput < SimpleForm::Inputs::Base
  def input
    template.content_tag(:div, class: 'form-group date time form_datetime') do
      template.concat @builder.text_field(attribute_name, date_input_html_options)
      template.concat @builder.text_field(attribute_name, time_input_html_options)
    end
  end

  def date_input_html_options
    options = {
      id: "#{attribute_name}_date",
      class: 'form-control datepicker',
      name: "#{object_name}[#{attribute_name}_date]",
      readonly: true,
      style: 'margin-right: 10px; width: auto; display: inline-block;'
    }

    options[:value] = @builder.object[attribute_name].strftime("%B %e, %Y") unless @builder.object[attribute_name].nil?
    options
  end

  def time_input_html_options
    options = {
      id: "#{attribute_name}_time",
      class: 'form-control timepicker',
      name: "#{object_name}[#{attribute_name}_time]",
      readonly: true,
      style: 'width: auto; display: inline-block;'
    }

    if @builder.object[attribute_name].nil?
      options[:value] = "12:00 AM"
    else
      options[:value] = @builder.object[attribute_name].strftime("%I:%M %p")
    end

    options
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
storytime-1.2.0 app/inputs/date_time_picker_input.rb
storytime-1.1.1 app/inputs/date_time_picker_input.rb
storytime-1.0.7 app/inputs/date_time_picker_input.rb
storytime-1.0.6 app/inputs/date_time_picker_input.rb
storytime-1.0.5 app/inputs/date_time_picker_input.rb
storytime-1.0.2 app/inputs/date_time_picker_input.rb
storytime-1.0.1 app/inputs/date_time_picker_input.rb
storytime-1.0.0 app/inputs/date_time_picker_input.rb