Module: AjaxValidator
- Defined in:
- app/models/ajax_validator/validator.rb,
lib/ajax_validator.rb,
lib/ajax_validator/engine.rb,
lib/ajax_validator/version.rb,
app/helpers/ajax_validator/application_helper.rb,
app/models/ajax_validator/concerns/validation.rb,
app/controllers/ajax_validator/validators_controller.rb,
app/controllers/ajax_validator/application_controller.rb
Overview
Use with form object that responds to ‘validate` method, e.g. use Reform or Virtus with ActiveModel::Validations
Open the console and try:
validator_params = { form_object: 'validations/signup_form_company_name',
resource_model: 'company',
resource_attr_name: 'name',
resource_attr_value: 'Efigence' }
One can use the engine with any ActiveModel::Model object with ActiveModel::Validations included. For performance, even if the model is clobbered with validations, only validations on the specified field one will be fired. Examples:
validator_params = { form_object: '',
resource_model: 'company',
resource_attr_name: 'name',
resource_attr_value: 'efigence' }
Validate (also conditionally) virtual or model attribute set inside some before validation callback:
validator_params = { form_object: '',
resource_model: 'company',
resource_attr_name: 'vat_number_with_prefix',
resource_attr_value: '',
ignore_resource_attr_value: 'true',
resource_instance_additional_params: {country: 'Poland',
vat_number: '0123456789'} }
validator_params = { form_object: '',
resource_model: 'company',
resource_attr_name: 'vat_number',
resource_attr_value: '',
ignore_resource_attr_value: 'true',
resource_instance_additional_params: {business_owner: true,
vat_number: ''} }
validator = AjaxValidator::Validator.new(validator_params) tested_company = validator.validate tested_company.errors.to_a
-
‘resource_instance_additional_params` hash is passed as args to given active model instance,
to handle before validation callbacks’ dependencies, however, if form object is used, additional params - if specified - must be handled by form object instance itself, implementations may vary.
-
set ‘ignore_resource_attr_value` to ’true’ if attribute value is assembled inside before validation
callback
-
validating virtual attributes, custom validation methods and custom validators are all supported
Defined Under Namespace
Modules: ApplicationHelper, Concerns Classes: ApplicationController, Engine, Validator, ValidatorsController
Constant Summary collapse
- VERSION =
"0.0.3"