Cannot read property ‘settings’ of undefined – jQuery snippet to solve the issue

Hi All, In this post, I would like to share my thoughts how to resolve the issue Cannot read property ‘settings’ of undefined in jQuery. It might be simple. But it took time to resolve this issue. It will easy for you when you stuck with these issues.

Cannot read property 'settings' of undefined - jQuery snippet to solve the issue by Anil Labs

Cannot read property ‘settings’ of undefined – jQuery snippet to solve the issue by Anil Labs

Generally, we add the jQuery attribute to add a rule for required like

jQuery code

$( "#attrName" ).rules( "add", "required");

If we use like we will get the issue like below

jQuery error

Uncaught TypeError: Cannot read property 'settings' of undefined
    at n.fn.init.rules (VM507 jquery.validate.min.js:4)
    at log (create:815)
    at Object.<anonymous> (create:616)
    at Function.each (jquery-2.1.3.min.js:2)
    at Object.<anonymous> (create:613)
    at j (jquery-2.1.3.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-2.1.3.min.js:2)
    at x (jquery-2.1.3.min.js:4)
    at XMLHttpRequest.<anonymous> (jquery-2.1.3.min.js:4)

So, to resolve this issue we need to change the adding rule to attribute

jQuery code to resolve

setTimeout(function() {
        $('#attrName').rules('add', { required: true });
}, 0);

This will resolve your issue. Hope it will solve your issue also.

Anil Kumar Panigrahi

With more than 10 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : [email protected]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.