blob: 8e698ef922cf3362d67a807a4e802a2c5dc154c8 (
plain) (
tree)
|
|
# frozen_string_literal: true
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
|