1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00
heartcombo--simple_form/lib/simple_form/helpers/pattern.rb

25 lines
638 B
Ruby
Raw Normal View History

module SimpleForm
module Helpers
# Helper methods for pattern.
module Pattern #:nodoc:
private
def add_pattern!
input_html_options[:pattern] ||= pattern_source if validate_pattern?
end
def validate_pattern?
has_validators? && SimpleForm.html5 &&
SimpleForm.browser_validations && pattern_validator.present?
end
def pattern_source
pattern_validator.options[:with].source
end
def pattern_validator
@pattern_validator ||= attribute_validators.find { |v| ActiveModel::Validations::FormatValidator === v }
end
end
end
end