Sha256: 644db3d91bce9838455e8856b1876b17cfd6cf6cf7504efa5eebebb76fda4473

Contents?: true

Size: 767 Bytes

Versions: 99

Compression:

Stored size: 767 Bytes

Contents

# frozen_string_literal: true

module ActionView
  module Helpers
    module Tags # :nodoc:
      class DatetimeField < TextField # :nodoc:
        def render
          options = @options.stringify_keys
          options["value"] ||= format_date(value)
          options["min"] = format_date(datetime_value(options["min"]))
          options["max"] = format_date(datetime_value(options["max"]))
          @options = options
          super
        end

        private
          def format_date(value)
            raise NotImplementedError
          end

          def datetime_value(value)
            if value.is_a? String
              DateTime.parse(value) rescue nil
            else
              value
            end
          end
      end
    end
  end
end

Version data entries

99 entries across 95 versions & 7 rubygems

Version Path
actionview-6.1.7.5 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.7 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.6 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.5.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.1.7.4 lib/action_view/helpers/tags/datetime_field.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/actionview-6.1.6.1/lib/action_view/helpers/tags/datetime_field.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/actionview-7.0.2.3/lib/action_view/helpers/tags/datetime_field.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/actionview-7.0.3.1/lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.5 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.4.3 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.1.7.3 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.1.7.2 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.4.2 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.4.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.1.7.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.0.6.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.4 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.1.7 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.0.6 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.3.1 lib/action_view/helpers/tags/datetime_field.rb