mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
05527de82e
Prevent erroning with `undefined method `source' for nil:NilClass` when format validation is a "without" one
34 lines
788 B
Ruby
34 lines
788 B
Ruby
module SimpleForm
|
|
module Components
|
|
# Needs to be enabled in order to do automatic lookups.
|
|
module Pattern
|
|
def pattern
|
|
input_html_options[:pattern] ||= pattern_source
|
|
nil
|
|
end
|
|
|
|
private
|
|
|
|
def pattern_source
|
|
pattern = options[:pattern]
|
|
if pattern.is_a?(String)
|
|
pattern
|
|
elsif (pattern_validator = find_pattern_validator) && (with = pattern_validator.options[:with])
|
|
evaluate_format_validator_option(with).source
|
|
end
|
|
end
|
|
|
|
def find_pattern_validator
|
|
find_validator(:format)
|
|
end
|
|
|
|
def evaluate_format_validator_option(option)
|
|
if option.respond_to?(:call)
|
|
option.call(object)
|
|
else
|
|
option
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|