aboutsummaryrefslogblamecommitdiffstats
path: root/actionview/lib/action_view/helpers/tags/color_field.rb
blob: b4bbe9274670f003ca6d7616f36eb37af409e708 (plain) (tree)
1
2
3
4
5
6
7

                 

                                            

                                           
                                                                   

















                                           
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