judgegem / judge

Client-side form validation for Rails
MIT License
256 stars 41 forks source link

Devise validation of an email address returns: 'is invalid' #32

Closed ChristofferJoergensen closed 9 years ago

ChristofferJoergensen commented 10 years ago

Great gem that you have shared with us!

I am having some problems validating the email attribute in my User model. I am using devise's validatable module to perform validation of the uniqueness of the email as well as some regex validations I guess.

When using judge on my form, I get back this 'is invalid' error when I enter any email into my form.

Any idea why this is?

My initializer:

Judge.configure do
  expose User, :email
end

My js:

judge.validate document.getElementById("user_email"),
  valid: (element) ->
    console.log "Good job"
  invalid: (element, messages) ->
    console.log messages.join(', ')

My form:

= form_for(resource, :builder => Judge::FormBuilder, :as => resource_name, :url => registration_path(resource_name)) do |f|
  = f.text_field :email, :validate => true

My log:

Started GET "/judge?klass=user&attribute=email&value=my%40email.com&kind=uniqueness" for 127.0.0.1 at 2014-06-03 18:44:37 +0200
Processing by Judge::ValidationsController#build as JSON
  Parameters: {"klass"=>"user", "attribute"=>"email", "value"=>"my@email.com", "kind"=>"uniqueness"}
Completed 200 OK in 5ms (Views: 0.2ms)

And when I remove the validatable module from my User model, no errors are returned.

Vadorequest commented 10 years ago

Take a look to this: https://github.com/joecorcoran/judge/issues/25

it was because of the regex itself for me.

ChristofferJoergensen commented 10 years ago

Thanks for your comment. But the problem for me is here that devise defines the email regex, and I would really like not to overwrite Devise validation functionality.

Vadorequest commented 10 years ago

This isue too could bring you more information about the issue, maybe your Device gem override the native regex way.

https://github.com/joecorcoran/judge/issues/19

ricardodovalle commented 10 years ago

@ChristofferJoergensen , same issue. Did you solve? Thanks

ChristofferJoergensen commented 10 years ago

Hi @ricardodovalle. No, I have not yet solved it. I am a little bit afraid of implementing some custom regex override. I feel like I should stick to the validations that Devise has implemented.

grammakov commented 10 years ago

Having the exact same issue.

tommyalvarez commented 10 years ago

+1 same issue.

codemilan commented 9 years ago

+1 same issue for devise validatable, how can we fix.

Gee-Bee commented 9 years ago

Same here. Judge mark any email as invalid. Devise regex: /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/ Judge generated regex: (?-mix:\\A[^@\\s]+@([^@\\s]+\\.)+[^@\\s]+\\z)

jamesmk commented 9 years ago

@ChristofferJoergensen There's nothing magical about Devise's validations, you can see them here: https://github.com/plataformatec/devise/blob/18b6064d74726147eccd69b24812000074261bbb/lib/devise/models/validatable.rb#L29

If you don't want to remove the validatable module complete, Devise offers a config in their initializer to just override the email regex:

# Email regex used to validate email formats. It simply asserts that
# one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
# config.email_regexp = /\A[^@]+@[^@]+\z/

As you see from the comments (and source here: https://github.com/plataformatec/devise/blob/18b6064d74726147eccd69b24812000074261bbb/lib/devise.rb#L108) their regex is actually pretty weak.

danieldocki commented 9 years ago

+1 same here with devise

jamesmk commented 9 years ago

fixed in https://github.com/joecorcoran/judge/issues/60