Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When my js page loads and I create a rule seen below I get a error thrown from the jquery.validate.js library line #138, that says "cannot read property 'settings' of undefined"

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

Here is the rule I'm adding and the form I'm adding it too

$('#zipCodeText').rules("add", {
  required: true,
  minlength: 5,
  maxlength: 5,
  messages: {
    required: "Required input",
    minlength: jQuery.validator.format("Please, {0} characters are necessary"),
    maxlength: jQuery.validator.format("Please, {0} characters are necessary")
  }
});
@using (Html.BeginForm("SaveLocation", "Manage", FormMethod.Post, new { @class = "form-horizontal", @id = "registerForm", role = "form" })) {
<div class="form-group">
  <label for="countryList">Country</label>
  <br />@Html.EnumDropDownListFor(m => m.Countries, null, new { @id = "countryList", @class = "selectpicker btn-group-lg" })
</div>

<div id="zipCodeGroup" class="form-group has-feedback" style="display: @(Model.Country == 0 ? " " : "none ");">
  <label for="zipCodeText">ZipCode</label>
  <input type="number" min="5" max="5" class="form-control input-lg" id="zipCodeText" placeholder="e.g. 94102" value="@Model.ZipCode">
  <label id="zipCodeMessage" style="display: none;"></label>
</div>
<div id="locationGroup" class="form-group has-feedback" style="display: @(Model.Country == 0 ? " none " : " ");">
  <label for="locationText">Location</label>
  <input type="text" min="4" max="40" class="form-control input-lg" id="locationText" placeholder="e.g. San Francisco" value="@Model.Location">
  <label id="locationMessage" style="display: none;"></label>
</div>

<input type="button" value="Save" id="yogaLocationSave" class="btn btn-primary btn-lg" />
<input type="button" value="Cancel" id="yogaLocationCancel" class="btn btn-default btn-lg" />}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
224 views
Welcome To Ask or Share your Answers For Others

1 Answer

JavaScript runtime error: Unable to get property 'settings' of undefined or null reference"

You must first initialize the plugin by calling the .validate() method on your form element.

$('#yourform').validate({ // <-- INITIALIZE the plugin on your form
    // any options, rules, or callbacks
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...