DavyJonesLocker / client_side_validations

Client Side Validations made easy for Ruby on Rails
MIT License
2.69k stars 403 forks source link

Uncaught TypeError: Cannot read property 'validators' of undefined #387

Closed mledom closed 12 years ago

mledom commented 12 years ago

I'm getting the Uncaught TypeError: Cannot read property 'validators' of undefined when trying to validate a field. I've trying to figure out where window.ClientSideValidations.forms is being populated with anything other than the initialization window.ClientSideValidations = { forms: {} I'm using:

mledom commented 12 years ago

I'm including both the rails.validations and rails.validations.simple_form as well

bcardarella commented 12 years ago

Can you try the master branch please and let me know if the same issue is happening.

kamelury commented 12 years ago

I have the same error, but only in edit form loaded via js. I tried both master and client_side_validations (3.2.0.beta.6). The edit form has the id: "edit_review_971" . Validations work fine for new_review forms loaded via js and for normally loaded edit forms.

Setup: rails 3.2.8 simple_form 2.0.2 client_side_validations-simple_form 2.0.0.beta.2

bcardarella commented 12 years ago

@kamelury would it be possible for you to create an example at demonstrating the problem? I cannot seem to recreate and this would be a huge help.

ansel1 commented 12 years ago

I was able to recreate this in my code, but it's because I'm hacking. I wanted to prevent a few form fields from being submitted to the server, so I was setting their "name" attributes to null in some js on page load. Once the elements have no names, they lose some of their wiring to their validations, and these errors result. Not sure if it's the same cause.

bcardarella commented 12 years ago

Yeah it will probably cause issues if the names are removed. Ideally the code should handle this gracefully. I'll see about covering this edge case.

jbodily commented 12 years ago

I had this same issue using the same stack and had to change clientSideValidations to capital ClientSideValidations in my custom javascript. Just in case that's relevant to anyone else's problems!

bcardarella commented 12 years ago

@jbodily the master branch changed the from clientSideValidations to ClientSideValidations. This is undocumented but I will make notes of it for upgrades when 3.2's RC comes out

kamelury commented 12 years ago

Thanks everyone for hints and suggestions. I found the origin of the problem while preparing an example for demonstration. In my case the issue had nothing to do with client_side_validations. It was the way the form html was inserted.

bcardarella commented 12 years ago

@mledom ca I get a follow up on this issue?

mledom commented 12 years ago

I will look at it tonight and get back to you then. Should I upgrade to the 3.2 RC?

mledom commented 12 years ago

didn't mean to close it, sorry.

bcardarella commented 12 years ago

@mledom if you could use the master branch on Github that would be great. Thank you!

mledom commented 12 years ago

Looks like that's working for me. Great work on getting 3.2 out there.

bcardarella commented 12 years ago

@mledom awesome, thank you very much for following up on this :)

AndriySand commented 7 years ago

I had the same error and then I found error there, I used <%= form_for @zipcode, html: { class: "form-horizontal", validate: true } do |f| %> when I replaced it with this code everything started work fine <%= form_for @zipcode, html: { class: "form-horizontal" }, validate: true do |f| %> Best wishes