Class: Campo::Plugins::JQueryValidation::Klass

Inherits:
Plugin
  • Object
show all
Defined in:
lib/campo/plugins/jqueryvalidation.rb

Overview

instance methods

Instance Method Summary collapse

Methods inherited from Plugin

#afters, #befores

Methods included from Pluggable

#after_output, #before_output, #extras, #on_plugin, #plugged_in

Constructor Details

#initialize(opts = {}) ⇒ Klass

Returns a new instance of Klass.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/campo/plugins/jqueryvalidation.rb', line 132

def initialize( opts={} )
  before_output do |fields,options|
    #find the form name(s)
    @jqv_form_names = fields.find_all{|x| x.kind_of? Campo::Form }.map{|x| x.attributes[:name]}
    @jqv_form_names << opts[:form] unless opts[:form].nil? || opts[:form].empty?
  end
  after_output do |output,options|
    # concat to the current output
    out = jquery_script_declaration + output
    Rules.reset
    out
  end
  on_plugin do
    # adds `validate` to Convenience, it's an easy way to get it where it needs to be
    Campo::Base.send(:include, Campo::Plugins::JQueryValidation::InstanceMethods::Convenience)
    # only for the outputter
    Campo::Outputter.send(:include, Campo::Plugins::JQueryValidation::InstanceMethods::Outputter)
  end
end