Sha256: 7574380bad0165fe732f0caec26c53e66352556a2cbf783c52a7ac44f2077cce

Contents?: true

Size: 584 Bytes

Versions: 4

Compression:

Stored size: 584 Bytes

Contents

module ActionView
  module Helpers
    module Tags # :nodoc:
      class ColorField < TextField # :nodoc:
        def render
          options = @options.stringify_keys
          options["value"] = @options.fetch("value") { validate_color_string(value(object)) }
          @options = options
          super
        end

        private

          def validate_color_string(string)
            regex = /#[0-9a-fA-F]{6}/
            if regex.match(string)
              string.downcase
            else
              "#000000"
            end
          end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
challah-1.0.0 vendor/bundle/gems/actionpack-4.0.0/lib/action_view/helpers/tags/color_field.rb
actionpack-4.0.0 lib/action_view/helpers/tags/color_field.rb
actionpack-4.0.0.rc2 lib/action_view/helpers/tags/color_field.rb
actionpack-4.0.0.rc1 lib/action_view/helpers/tags/color_field.rb