Sha256: 512ce2e154ad063d6f3a40ab145f906477a62a0ec597623bf92bd3bd1e7d13c1

Contents?: true

Size: 558 Bytes

Versions: 151

Compression:

Stored size: 558 Bytes

Contents

module ActionView
  module Helpers
    module Tags # :nodoc:
      class ColorField < TextField # :nodoc:
        def render
          options = @options.stringify_keys
          options["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

151 entries across 146 versions & 11 rubygems

Version Path
actionview-4.2.11.3 lib/action_view/helpers/tags/color_field.rb
actionview-4.2.11.2 lib/action_view/helpers/tags/color_field.rb
actionview-5.1.7 lib/action_view/helpers/tags/color_field.rb
actionview-5.1.7.rc1 lib/action_view/helpers/tags/color_field.rb
actionview-5.1.6.2 lib/action_view/helpers/tags/color_field.rb
actionview-5.0.7.2 lib/action_view/helpers/tags/color_field.rb
actionview-4.2.11.1 lib/action_view/helpers/tags/color_field.rb
actionview-5.1.6.1 lib/action_view/helpers/tags/color_field.rb
actionview-5.0.7.1 lib/action_view/helpers/tags/color_field.rb
actionview-4.2.11 lib/action_view/helpers/tags/color_field.rb
actionview-5.1.6 lib/action_view/helpers/tags/color_field.rb
actionview-5.0.7 lib/action_view/helpers/tags/color_field.rb
actionview-5.1.5 lib/action_view/helpers/tags/color_field.rb
actionview-5.1.5.rc1 lib/action_view/helpers/tags/color_field.rb
actionview-4.2.10 lib/action_view/helpers/tags/color_field.rb
actionview-4.2.10.rc1 lib/action_view/helpers/tags/color_field.rb
actionview-5.1.4 lib/action_view/helpers/tags/color_field.rb
actionview-5.0.6 lib/action_view/helpers/tags/color_field.rb
actionview-5.1.4.rc1 lib/action_view/helpers/tags/color_field.rb
actionview-5.0.6.rc1 lib/action_view/helpers/tags/color_field.rb