Skip to content

Fixed "Cannot read property 'settings'" error #1970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

devgnx
Copy link

@devgnx devgnx commented Mar 8, 2017

First of all, sorry for my horrible english.

I've been facing the problem on a project and searched for work-arounds on the web, but none of them lead to a right solution.

When I try to post a specific form the plugin is returning: "Cannot read property 'settings' of undefined";

Found that the problem was my code, it has a form inside another form. But that's not clear from the message above.
Instead of returning the error, I made a change to check if the property exists on the current form.
'Couse after all, this plug in is not to validate my HTML, it's made to validate my inputs.

Thanks for the awesome plugin.

Some links:
#1076
#401
#917
#86

https://elnibs.wordpress.com/2013/10/22/jquery-validation-issue-cannot-read-property-settings-of-undefined/
https://forums.asp.net/t/1853275.aspx?+Cannot+read+property+settings+of+undefined+error+when+adding+a+rule+to+validator

First of all, sorry for my horrible english.

I've been facing the problem on a project and searched for work-arounds on the web, but none of them lead to a right solution.

When I try to post a specific form the plugin is returning: "Cannot read property 'settings' of undefined";

Found that the problem was my code, it has a form inside another form. But that's not clear from the message above.
Instead of returning the error, I made a change to check if the property exists on the current form.
'Couse after all, this plug in is not to validate my HTML, it's made to validate my inputs.

Thanks for the awesome plugin.

Some links:
jquery-validation#1076
jquery-validation#401
jquery-validation#917
jquery-validation#86

https://elnibs.wordpress.com/2013/10/22/jquery-validation-issue-cannot-read-property-settings-of-undefined/
https://forums.asp.net/t/1853275.aspx?+Cannot+read+property+settings+of+undefined+error+when+adding+a+rule+to+validator
@Arkni
Copy link
Member

Arkni commented Apr 6, 2017

Found that the problem was my code, it has a form inside another form. But that's not clear from the message above.

What do you think about throwing an error that describe the issue. Something like this:

It looks like you're calling a plugin method on an element outside the form
that was used to initialize the plugin.
Please make sure to call the plugin methods on elements that are part of
the initial form.

@staabm
Copy link
Member

staabm commented Apr 10, 2017

@Arkni I like the error message.. At best we also name the form by id and/or name in the error messages so it gets obvious which forms are part of the game.

@Arkni
Copy link
Member

Arkni commented Mar 4, 2018

Finally circling back to this.

After reinvestigating the issue, I found that what I suggested in my previous comment apply to the case when the developer called a plugin method on an element of another form, which is totally different from the issue that the OP was trying to fix.

I did some test and created a proper fix with tests. I will close this PR in favor of #2147.

@gnxdev thanks a lot for opening this PR and sorry for not merging it.

@Arkni Arkni closed this Mar 4, 2018
Arkni added a commit to Arkni/jquery-validation that referenced this pull request Mar 4, 2018
Arkni added a commit that referenced this pull request Mar 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants