Sha256: dbdad0580836bf1de6232ec7e199f17c077851487f545235cc4398feaae9609b

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

module SimpleForm
  module Inputs
    class DatePickerInput < Base
      def input
        @builder.datetime_field(attribute_name, input_html_options)
      end

      private

      def input_html_options
        if options.key?(:input_html) && options[:input_html].key?(:value)
          value = options[:input_html][:value]
        elsif options.key? :value
          value = options[:value]
        elsif object.respond_to?(attribute_name)
          value = object.send(attribute_name)
        else
          value = ''
        end

        value = Time.zone.parse(value) if value.is_a?(String)
        value = value.strftime("%Y-%m-%d") if value.respond_to?(:strftime)

        result = { class: 'form-control text-center date datepicker', value: value.presence || '' }
        if options.key? :input_html
          result[:class] += ' ' + options[:input_html][:class] if options[:input_html][:class].present?
          result.merge(options[:input_html].except(:class, :value))
        else
          result
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
simple_form_bootstrap3-0.3.5 lib/simple_form/inputs/date_picker_input.rb
simple_form_bootstrap3-0.3.4 lib/simple_form/inputs/date_picker_input.rb
simple_form_bootstrap3-0.3.3 lib/simple_form/inputs/date_picker_input.rb
simple_form_bootstrap3-0.3.2 lib/simple_form/inputs/date_picker_input.rb
simple_form_bootstrap3-0.3.1 lib/simple_form/inputs/date_picker_input.rb