Class: BootstrapValidatorRails::Validators::Format

Inherits:
Validator
  • Object
show all
Defined in:
lib/bootstrap_validator_rails/validators/format_validator.rb

Instance Method Summary collapse

Methods inherited from Validator

#generate_message, #generate_object, #html_attributes, #initialize, #js_options, #unsupported?, #validator_options

Constructor Details

This class inherits a constructor from BootstrapValidatorRails::Validators::Validator

Instance Method Details

#generate_options!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bootstrap_validator_rails/validators/format_validator.rb', line 11

def generate_options!
  return if unsupported?
  
  options = validator_options

  regex = options[:with].to_javascript
  regex.sub!('/^', '^')
  regex.sub!('$/', '$')
  
  @js_options['regexp'] = {}
  @html_attributes[:bv_regexp] = 'true'

  if options[:with]
    @js_options['regexp']['regexp'] = regex
    @html_attributes[:bv_regexp_regexp] = regex 
  end

  if options[:message]
    @js_options['regexp']['message'] = generate_message
    @html_attributes[:bv_regexp_message] = generate_message
  end
end