From f7235328a1cd1d98a6399906ecbb0dec9fb3ebb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gon=C3=A7alves?= Date: Wed, 8 Mar 2017 11:43:25 -0300 Subject: [PATCH] Fixed "Cannot read property 'settings'" error 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: https://github.com/jquery-validation/jquery-validation/issues/1076 https://github.com/jquery-validation/jquery-validation/issues/401 https://github.com/jquery-validation/jquery-validation/issues/917 https://github.com/jquery-validation/jquery-validation/issues/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 --- src/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index 8ceb40fc7..643a04e74 100644 --- a/src/core.js +++ b/src/core.js @@ -1230,7 +1230,7 @@ $.extend( $.validator, { var rules = {}, validator = $.data( element.form, "validator" ); - if ( validator.settings.rules ) { + if ( validator && validator.settings && validator.settings.rules ) { rules = $.validator.normalizeRule( validator.settings.rules[ element.name ] ) || {}; } return rules;