bcardarella/client_side_validations — Issue #277: custom validations broken
Author: ak2196
Created: 2012-02-17 05:17:54+00:00
State: open

I am using Rails 3.2.1 w/ 3.2.0.beta.2.

Here is the custom validator. It works fine server side.

class EmailFormatValidator < ActiveModel::EachValidator
def validate_each(object, attribute, value)
unless value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
object.errors.add(attribute, :email_format, options)
end
end
end

Here is the custom js validation:

clientSideValidations.validators.local["email_format"] = function (element, options) {
if(!/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i.test(element.val())) {
return options.message;
}
}

All the other client side validations work except for this one. However, once I resolve the other and submit, this one triggers. So everything is fine on my end. Seems like a bug. Any ideas?