blob: 69b190809ff56b41713317b63ae5ea3ec3a80619 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# 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)
@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
|