Skip to content
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

Uncaught TypeError: Cannot read property 'settings' of undefined #2158

Closed
tanvan81 opened this issue Mar 31, 2018 · 11 comments
Closed

Uncaught TypeError: Cannot read property 'settings' of undefined #2158

tanvan81 opened this issue Mar 31, 2018 · 11 comments
Labels
NEEDS FEEDBACK stale Used to mark stale issues

Comments

@tanvan81
Copy link

I have code

` function initValidateQuestion() {
var submitSettings = $.data($("#frmQuestion").get(0), 'validator').settings;

        submitSettings.messages = {
            Content: {
                required: "....."
            },
            FullName: {
                required: "xxxx"
            },
            Email: {
                required: "xxxxx"
            },
        };
    }

`

This code run on Jquery 2.x. But when I upgrapde jquery 3.3.1, I run this code, get error

jQuery.Deferred exception: Cannot read property 'settings' of undefined TypeError: Cannot read property 'settings' of undefined

Uncaught TypeError: Cannot read property 'settings' of undefined

How do I fix this bug ???

@DoomerDGR8
Copy link

Same issue here.

@Arkni
Copy link
Member

Arkni commented May 29, 2018

Hi @tanvan81 & @hassangulzar

I think we have this fixed in master, but not released yet. Could you please test with the version in master and see if the issue persist. You can grab the dist file from this gist: https://gist.github.com/Arkni/495730a47b52b570b150d4375bfbb7c7

Thanks!

@Chealer
Copy link

Chealer commented Jul 16, 2018

This is similar to issue #1267 .

@Chealer
Copy link

Chealer commented Jul 16, 2018

I am seeing this error with 1.13:
jquery.validate.js:1278 Uncaught TypeError: Cannot read property 'settings' of undefined
at Function.staticRules (jquery.validate.js:1278)
at jQuery.fn.init.rules (jquery.validate.js:196)
at HTMLInputElement. (jquery.validate.js:665)
at jquery.js:2816
at Function.grep (jquery.js:424)
at winnow (jquery.js:2815)
at jQuery.fn.init.filter (jquery.js:2879)
at $.validator.elements (jquery.validate.js:647)
at $.validator.checkForm (jquery.validate.js:464)
at $.validator.form (jquery.validate.js:452)

staticRules | @ | jquery.validate.js:1278
  | rules | @ | jquery.validate.js:196
  | (anonymous) | @ | jquery.validate.js:665
  | (anonymous) | @ | jquery.js:2816
  | grep | @ | jquery.js:424
  | winnow | @ | jquery.js:2815
  | filter | @ | jquery.js:2879
  | elements | @ | jquery.validate.js:647
  | checkForm | @ | jquery.validate.js:464
  | form | @ | jquery.validate.js:452
  | (anonymous) | @ | jquery.validate.js:105
  | dispatch | @ | jquery.js:5183
  | elemData.handle | @ | jquery.js:4991
  | trigger | @ | jquery.js:8288
  | (anonymous) | @ | jquery.js:8327
  | each | @ | jquery.js:354
  | each | @ | jquery.js:189
  | trigger | @ | jquery.js:8326
  | jQuery.fn.(anonymous function) | @ | jquery.js:10212
  | (anonymous) | @ | tiki-jquery.js:3310
  | dispatch | @ | jquery.js:5183
  | elemData.handle | @ | jquery.js:4991

The error still occurs with the file offered by Arkni.

@Arkni Arkni mentioned this issue Jul 20, 2018
@Matthewsre
Copy link

Matthewsre commented Sep 12, 2018

I upgraded jquery to 3.3.1 and started getting this same error. I tried the 1.17.1-pre file and the issue persists.

Happens from calling the following:

$("#contacts-validation").rules("add", "primaryContact");

Loaded up the non-minified version of 1.17.0 and generated to get the line number:

Uncaught TypeError: Cannot read property 'settings' of undefined
at jQuery.fn.init.rules (jquery.validate.js:162)

Looks like the offending line for me is here:

settings = $.data( element.form, "validator" ).settings;

EDIT: My issue was from missing the script include for jquery.validate.unobtrusive in an ASP.NET Core application. Added that and all is well.

@tanvan81
Copy link
Author

tanvan81 commented Mar 30, 2020

Still error

I've jquery.validate.1.19.min.js. When I call ajax

` function addContact(id) {
$.ajax({
url: "@Url.Action("AddContact", "managecontact")",
type: "POST",
data: {
Id: id
},
success: function (msg) {
$("#dvEdit").html(msg);
$("#dvEdit")
.dialog({
modal: true,
title: (id == 0 ? "Add contact" : "Edit contact")
}).dialog("open");

                $("#frmEdit").removeData("validator");
                $.validator.unobtrusive.parse(document);
                initValidate();
            }
        })
    }`

` function initValidate() {
var submitSettings = $.data($("#frmEdit").get(0), 'validator').settings;
submitSettings.rules = {
Email: {
email: true,
},
};

        submitSettings.messages = {
            Email: {
                required: "Please input email",
                email: "Email not correct",
            },
            FullName: {
                required: "Please input name"
            }
        };
    }`

when success, console error
Cannot read property 'settings' of undefined

@tanvan81 tanvan81 reopened this Mar 30, 2020
@tanvan81
Copy link
Author

Still error

@Lefthandmedia
Copy link

me too still error

@nivle
Copy link

nivle commented Oct 23, 2020

For some reason, a form with no fields to validate(empty form), gives this error(on my end at least...)...

Another possible cause is not calling the "validate()" method on your form first, before doing other things.(this seems to set up some stuff...)

ex: $("#myFormId").validate();

@edika99
Copy link

edika99 commented Nov 13, 2020

Same here.

Uncaught TypeError: Cannot read property 'settings' of undefined
at init.rules (jquery.validate.js:164)
at HTMLInputElement. (buyshares.js:22)
at HTMLInputElement.dispatch (jquery-1.10.2.min.js:5)
at HTMLInputElement.v.handle (jquery-1.10.2.min.js:5)

when trying to add a simple rule

$("#txtisin").rules('add', { required: true});

@github-actions
Copy link

This issue/proposal has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automatically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up.
Thank you for contributing :)

@github-actions github-actions bot added the stale Used to mark stale issues label Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NEEDS FEEDBACK stale Used to mark stale issues
Projects
None yet
Development

No branches or pull requests

8 participants