Skip to content

Commit 0d81f3e

Browse files
authored
Add requirement for jQuery Validation's additional-methods (#18207)
1 parent 0ddceca commit 0d81f3e

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

aspnetcore/mvc/models/validation.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Validation attributes let you specify validation rules for model properties. The
4545

4646
Here are some of the built-in validation attributes:
4747

48-
* `[CreditCard]`: Validates that the property has a credit card format.
48+
* `[CreditCard]`: Validates that the property has a credit card format. Requires [jQuery Validation Additional Methods](https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/additional-methods.min.js).
4949
* `[Compare]`: Validates that two properties in a model match.
5050
* `[EmailAddress]`: Validates that the property has an email format.
5151
* `[Phone]`: Validates that the property has a telephone number format.
@@ -112,7 +112,7 @@ The `[Remote]` attribute implements client-side validation that requires calling
112112

113113
To implement remote validation:
114114

115-
1. Create an action method for JavaScript to call. The jQuery Validate [remote](https://jqueryvalidation.org/remote-method/) method expects a JSON response:
115+
1. Create an action method for JavaScript to call. The jQuery Validation [remote](https://jqueryvalidation.org/remote-method/) method expects a JSON response:
116116

117117
* `true` means the input data is valid.
118118
* `false`, `undefined`, or `null` means the input is invalid. Display the default error message.
@@ -238,7 +238,7 @@ Client-side validation avoids an unnecessary round trip to the server when there
238238

239239
[!code-cshtml[](validation/samples/3.x/ValidationSample/Views/Shared/_ValidationScriptsPartial.cshtml?name=snippet_Scripts)]
240240

241-
The [jQuery Unobtrusive Validation](https://github.com/aspnet/jquery-validation-unobtrusive) script is a custom Microsoft front-end library that builds on the popular [jQuery Validate](https://jqueryvalidation.org/) plugin. Without jQuery Unobtrusive Validation, you would have to code the same validation logic in two places: once in the server-side validation attributes on model properties, and then again in client-side scripts. Instead, [Tag Helpers](xref:mvc/views/tag-helpers/intro) and [HTML helpers](xref:mvc/views/overview) use the validation attributes and type metadata from model properties to render HTML 5 `data-` attributes for the form elements that need validation. jQuery Unobtrusive Validation parses the `data-` attributes and passes the logic to jQuery Validate, effectively "copying" the server-side validation logic to the client. You can display validation errors on the client using tag helpers as shown here:
241+
The [jQuery Unobtrusive Validation](https://github.com/aspnet/jquery-validation-unobtrusive) script is a custom Microsoft front-end library that builds on the popular [jQuery Validation](https://jqueryvalidation.org/) plugin. Without jQuery Unobtrusive Validation, you would have to code the same validation logic in two places: once in the server-side validation attributes on model properties, and then again in client-side scripts. Instead, [Tag Helpers](xref:mvc/views/tag-helpers/intro) and [HTML helpers](xref:mvc/views/overview) use the validation attributes and type metadata from model properties to render HTML 5 `data-` attributes for the form elements that need validation. jQuery Unobtrusive Validation parses the `data-` attributes and passes the logic to jQuery Validation, effectively "copying" the server-side validation logic to the client. You can display validation errors on the client using tag helpers as shown here:
242242

243243
[!code-cshtml[](validation/samples/3.x/ValidationSample/Pages/Movies/Create.cshtml?name=snippet_ReleaseDate&highlight=3-4)]
244244

@@ -255,7 +255,7 @@ The preceding tag helpers render the following HTML:
255255
</div>
256256
```
257257

258-
Notice that the `data-` attributes in the HTML output correspond to the validation attributes for the `Movie.ReleaseDate` property. The `data-val-required` attribute contains an error message to display if the user doesn't fill in the release date field. jQuery Unobtrusive Validation passes this value to the jQuery Validate [required()](https://jqueryvalidation.org/required-method/) method, which then displays that message in the accompanying **\<span>** element.
258+
Notice that the `data-` attributes in the HTML output correspond to the validation attributes for the `Movie.ReleaseDate` property. The `data-val-required` attribute contains an error message to display if the user doesn't fill in the release date field. jQuery Unobtrusive Validation passes this value to the jQuery Validation [required()](https://jqueryvalidation.org/required-method/) method, which then displays that message in the accompanying **\<span>** element.
259259

260260
Data type validation is based on the .NET type of a property, unless that is overridden by a `[DataType]` attribute. Browsers have their own default error messages, but the jQuery Validation Unobtrusive Validation package can override those messages. `[DataType]` attributes and subclasses such as `[EmailAddress]` let you specify the error message.
261261

@@ -265,7 +265,7 @@ For information on unobtrusive validation, see [this GitHub issue](https://githu
265265

266266
### Add Validation to Dynamic Forms
267267

268-
jQuery Unobtrusive Validation passes validation logic and parameters to jQuery Validate when the page first loads. Therefore, validation doesn't work automatically on dynamically generated forms. To enable validation, tell jQuery Unobtrusive Validation to parse the dynamic form immediately after you create it. For example, the following code sets up client-side validation on a form added via AJAX.
268+
jQuery Unobtrusive Validation passes validation logic and parameters to jQuery Validation when the page first loads. Therefore, validation doesn't work automatically on dynamically generated forms. To enable validation, tell jQuery Unobtrusive Validation to parse the dynamic form immediately after you create it. For example, the following code sets up client-side validation on a form added via AJAX.
269269

270270
```javascript
271271
$.get({
@@ -284,7 +284,7 @@ $.get({
284284
})
285285
```
286286

287-
The `$.validator.unobtrusive.parse()` method accepts a jQuery selector for its one argument. This method tells jQuery Unobtrusive Validation to parse the `data-` attributes of forms within that selector. The values of those attributes are then passed to the jQuery Validate plugin.
287+
The `$.validator.unobtrusive.parse()` method accepts a jQuery selector for its one argument. This method tells jQuery Unobtrusive Validation to parse the `data-` attributes of forms within that selector. The values of those attributes are then passed to the jQuery Validation plugin.
288288

289289
### Add Validation to Dynamic Controls
290290

@@ -300,7 +300,7 @@ $.get({
300300
success: function(newInputHTML) {
301301
var form = document.getElementById("my-form");
302302
form.insertAdjacentHTML("beforeend", newInputHTML);
303-
$(form).removeData("validator") // Added by jQuery Validate
303+
$(form).removeData("validator") // Added by jQuery Validation
304304
.removeData("unobtrusiveValidation"); // Added by jQuery Unobtrusive Validation
305305
$.validator.unobtrusive.parse(form);
306306
}
@@ -309,11 +309,11 @@ $.get({
309309

310310
## Custom client-side validation
311311

312-
Custom client-side validation is done by generating `data-` HTML attributes that work with a custom jQuery Validate adapter. The following sample adapter code was written for the `[ClassicMovie]` and `[ClassicMovieWithClientValidator]` attributes that were introduced earlier in this article:
312+
Custom client-side validation is done by generating `data-` HTML attributes that work with a custom jQuery Validation adapter. The following sample adapter code was written for the `[ClassicMovie]` and `[ClassicMovieWithClientValidator]` attributes that were introduced earlier in this article:
313313

314314
[!code-javascript[](validation/samples/3.x/ValidationSample/wwwroot/js/classicMovieValidator.js)]
315315

316-
For information about how to write adapters, see the [jQuery Validate documentation](https://jqueryvalidation.org/documentation/).
316+
For information about how to write adapters, see the [jQuery Validation documentation](https://jqueryvalidation.org/documentation/).
317317

318318
The use of an adapter for a given field is triggered by `data-` attributes that:
319319

0 commit comments

Comments
 (0)