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

#initialize, #unsupported?, #validator_options

Constructor Details

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

Instance Method Details

#generate_dataObject



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

def generate_data
  data = {}
  return data if unsupported?
  
  options = validator_options

  regex = options[:with].to_javascript
  regex.sub!('/^', '^')
  regex.sub!('$/', '$')
  
  data[:bv_regexp] = 'true'

  if options[:with]
    data[:bv_regexp_regexp] = regex 
  end

  if options[:message]
    data[:bv_regexp_message] = options[:message] 
  end

  data
end