Sha256: 9ccfb72ad49338eef4e64d5293a332fe3f268ee345a388b457096910b8bccecb
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
require 'bootstrap_validator_rails/engine' require 'bootstrap_form' module BootstrapValidatorRails class FormBuilder < BootstrapForm::FormBuilder def validators_of(method) object.class.validators_on(method) end def generate_validation_message(method, type) object.errors.generate_message(method, type, default: "is invalid") end def text_field(method, options = {}) validators = validators_of(method) validator_messages = {} validators.each do |validator| if validator.kind == :presence validator_messages[:mv_notempty] = '' validator_messages[:mv_notempty_message] = generate_validation_message(method, validator.kind) elsif validator.kind == :numericality validator_messages[:mv_numeric_separator] = '' validator_messages[:mv_numeric_separator_message] = generate_validation_message(method, validator.kind) end end options[:data] = {} options[:data] = options[:data].merge(validator_messages) super end end end module BootstrapValidatorRails module Helper def validated_bootstrap_form_for(object, options = {}, &block) options.reverse_merge!({builder: BootstrapValidatorRails::FormBuilder}) bootstrap_form_for(object, options, &block) end end end ActionView::Base.send :include, BootstrapValidatorRails::Helper
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bootstrap_validator_rails-0.0.5 | lib/bootstrap_validator_rails.rb |