javascript - custom remote validator with client_side_validations -


i trying build custom remote validator using client_side_validations based on tutorial. far have this:

config/initializers/custom_validators.rb

class jobsoverlapvalidator < activemodel::eachvalidator   def validate_each(record, attr_name, value)    #validation code   end end  # allows assign validator in model module activemodel::validations::helpermethods   def validates_jobs_overlap(*attr_names)     validates_with jobsoverlapvalidator, _merge_attributes(attr_names)   end end 

app/models/job.rb

class job < activerecord::base   ...   validates_jobs_overlap :starts_at   ... end 

app/middleware/client_side_validations/jobs_overlap.rb

module clientsidevalidations   module middleware     class jobsoverlap < base       def response          ....          if true           self.status = 200         else           self.status = 404         end         super       end     end   end end 

app/assets/javascripts/rails.validations.custom.js

clientsidevalidations.validators.remote['jobs_overlap'] = function(element, options) {   if ($.ajax({     url: '/validators/jobs_overlap',     data: { id: element.val() },     // async *must* false     async: false   }).status == 404) { return options.message; } } 

app/assets/javascript/application.js

//= require jquery //= require jquery-ui //= require jquery_ujs //= require jquery_nested_form //= require application/rails.validations //= require application/rails.validations.nested_form //= require application/rails.validations.custom ... 

i believe problem custom validation not contained in script generated client_side_validations:

//<![cdata[ if(window.clientsidevalidations===undefined)window.clientsidevalidations={};window.clientsidevalidations.disabled_validators=[];window.clientsidevalidations.number_format={"separator":".","delimiter":","};if(window.clientsidevalidations.patterns===undefined)window.clientsidevalidations.patterns = {};window.clientsidevalidations.patterns.numericality=/^(-|\+)?(?:\d+|\d{1,3}(?:\,\d{3})+)(?:\.\d*)?$/;if(window.clientsidevalidations.remote_validators_prefix===undefined)window.clientsidevalidations.remote_validators_prefix='';if(window.clientsidevalidations.forms===undefined)window.clientsidevalidations.forms={};window.clientsidevalidations.forms['jobs_modal_form'] = {"type":"actionview::helpers::formbuilder","input_tag":"<div class='control-group error'><span id=\"input_tag\" ></span><span class=\"help-inline\"></span></div>","label_tag":"<div class='control-group error'><label id=\"label_tag\" ></label><span class=\"help-inline\"></span></div>","validators":{"job[client_attributes][name]":{"presence":[{"message":"can't blank"}],"length":[{"messages":{"maximum":"is long (maximum 50 characters)"},"maximum":50}]},"job[client_attributes][contact_name]":{"length":[{"messages":{"maximum":"is long (maximum 50 characters)"},"maximum":50}]},"job[client_attributes][contact_phone]":{"length":[{"messages":{"maximum":"is long (maximum 50 characters)"},"maximum":50}]},"job[client_attributes][contact_email]":{"format":[{"message":"is invalid","with":/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i,"allow_blank":true}],"length":[{"messages":{"maximum":"is long (maximum 50 characters)"},"maximum":50}]},"job[client_attributes][address]":{"length":[{"messages":{"maximum":"is long (maximum 100 characters)"},"maximum":100}]},"job[description]":{"presence":[{"message":"can't blank"}],"length":[{"messages":{"maximum":"is long (maximum 500 characters)"},"maximum":500}]}}}; //]]> 

does ever encountered similar issue? why client_side_validations doesn't create validations same way others created on client? help, stuck on issue , have no idea how continue :).


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -