Module: GLiveValidator::ViewHelpers
- Defined in:
- lib/g_live_validator/view_helpers.rb
Constant Summary collapse
- G_VALIDATION_METHODS =
{ :presence => "Validate.Presence", :numericality => "Validate.Numericality", :format => "Validate.Format", :length => "Validate.Length", :size => "Validate.Length", :acceptance => "Validate.Acceptance", :confirmation => "Validate.Confirmation", :exclusion => "Validate.Exclusion" }
Instance Method Summary collapse
-
#g_live_dynamic_validator(form, validation_rules, *args) ⇒ Object
Guilded component.
-
#g_live_validator(form, *args) ⇒ Object
Guilded component.
Instance Method Details
#g_live_dynamic_validator(form, validation_rules, *args) ⇒ Object
Guilded component. The live dynamic validator accepts an array of ValidationDefinition objects and sets up the live validations accordingly. This makes the live dynamic validator usable with the midas-dynamic_validations gem and possibly other validations that can be standardized through the ValidationDefinition object.
The same validations that are supported by the g_live_validator are also supported.
If you need to do custom initialization you can implement g.beforeLiveValidatorInit() or g.afterLiveValidatorInit() in the client side JavaScript environment.
If you need custom handling of valid or invalid fields, you can implement g.liveValidatorInvalidField() or g.liveValidatorValidField() in the client side JavaScript environment.
parameters
- form
-
The form object from the form_for helper.
options
- id
-
(required)
- except
-
List of fields to not include. A string, symbol or array of strings or symbols.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/g_live_validator/view_helpers.rb', line 81 def g_live_dynamic_validator( form, validation_rules, *args ) = args. klass = form.object.class class_name = klass.to_s.downcase .merge! :id => "live-validator-#{class_name}" ar_obj_name = form.object.class.to_s.underscore validation_defs = validation_rules.map { |validation_rule| ValidationDefinition.new( validation_rule ) } validations = g_map_validations( validation_defs ) validations = ( form, validations, ar_obj_name, ) .merge! :validations => validations Guilded::Guilder.instance.add( :live_validator, , [ 'livevalidation-1.3.min.js' ] ) return "" end |
#g_live_validator(form, *args) ⇒ Object
Guilded component. This reads from the server side validations and sets up client side validations that match utilizing the Live Validation library. The following validation macros and args are implemented:
validates_presence_of - :message validates_numericality_of - :less_than, :less_than_or_equal_to, :equal_to, :greater_than,
:greater_then_or_equal_to, :only_integer, :notANumberMessage, :notAnIntegerMessage,
:wrongNumberMessage, :tooLowMessage, :tooHighMessage
validates_length_of / validates_size_of - :maximum, :minimum, :is, :within, :in, :too_long,
:too_short, :wrong_length
validates_confirmation_of - Only works for 2 fields, no more or less. validates_acceptance_of - :message validates_inclusion_of - :message validates_exclusion_of - :message
If you need to do custom initialization you can implement g.beforeLiveValidatorInit() or g.afterLiveValidatorInit() in the client side JavaScript environment.
If you need custom handling of valid or invalid fields, you can implement g.liveValidatorInvalidField() or g.liveValidatorValidField() in the client side JavaScript environment.
parameters
- form
-
The form object from the form_for helper.
options
- id
-
(required)
- except
-
List of fields to not include. A string, symbol or array of strings or symbols.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/g_live_validator/view_helpers.rb', line 43 def g_live_validator( form, *args ) = args. klass = form.object.class class_name = klass.to_s.downcase .merge! :id => "live-validator-#{class_name}" ar_obj_name = form.object.class.to_s.underscore # TODO: Add human names to options #options.merge! :human_names => form.object validations = g_map_validations( klass.reflect_on_all_validations ) validations = ( form, validations, ar_obj_name, ) .merge! :validations => validations Guilded::Guilder.instance.add( :live_validator, , [ 'livevalidation-1.3.min.js' ] ) return "" end |