@abp/jquery-validation-unobtrusive 10.7.0-rc.5 → 11.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/License.txt ADDED
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) .NET Foundation and Contributors
4
+
5
+ All rights reserved.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
2
  mappings: {
3
- "@node_modules/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.js": "@libs/jquery-validation-unobtrusive/"
3
+ "@node_modules/@abp/jquery-validation-unobtrusive/src/jquery.validate.unobtrusive.js": "@libs/jquery-validation-unobtrusive/"
4
4
  }
5
5
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "10.7.0-rc.5",
2
+ "version": "11.0.0-rc.1",
3
3
  "name": "@abp/jquery-validation-unobtrusive",
4
4
  "repository": {
5
5
  "type": "git",
@@ -10,8 +10,8 @@
10
10
  "access": "public"
11
11
  },
12
12
  "dependencies": {
13
- "@abp/jquery-validation": "~10.7.0-rc.5",
14
- "jquery-validation-unobtrusive": "^4.0.0"
13
+ "@abp/jquery-validation": "~11.0.0-rc.1",
14
+ "jquery-validation": "^1.22.1"
15
15
  },
16
16
  "gitHead": "bb4ea17d5996f01889134c138d00b6c8f858a431",
17
17
  "homepage": "https://abp.io",
@@ -0,0 +1,436 @@
1
+ /**
2
+ * @license
3
+ * Unobtrusive validation support library for jQuery and jQuery Validate
4
+ * Copyright (c) .NET Foundation. All rights reserved.
5
+ * Licensed under the MIT License. See License.txt in the package root for license information.
6
+ * @version v4.0.0
7
+ * Patched copy: uses JSON.parse, typeof and Function.prototype.bind instead of the jQuery APIs removed or deprecated in jQuery 4.
8
+ */
9
+
10
+ /*jslint white: true, browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: false */
11
+ /*global document: false, jQuery: false */
12
+
13
+ (function (factory) {
14
+ if (typeof define === 'function' && define.amd) {
15
+ // AMD. Register as an anonymous module.
16
+ define("jquery.validate.unobtrusive", ['jquery-validation'], factory);
17
+ } else if (typeof module === 'object' && module.exports) {
18
+ // CommonJS-like environments that support module.exports
19
+ module.exports = factory(require('jquery-validation'));
20
+ } else {
21
+ // Browser global
22
+ jQuery.validator.unobtrusive = factory(jQuery);
23
+ }
24
+ }(function ($) {
25
+ var $jQval = $.validator,
26
+ adapters,
27
+ data_validation = "unobtrusiveValidation";
28
+
29
+ function setValidationValues(options, ruleName, value) {
30
+ options.rules[ruleName] = value;
31
+ if (options.message) {
32
+ options.messages[ruleName] = options.message;
33
+ }
34
+ }
35
+
36
+ function splitAndTrim(value) {
37
+ return value.replace(/^\s+|\s+$/g, "").split(/\s*,\s*/g);
38
+ }
39
+
40
+ function escapeAttributeValue(value) {
41
+ // As mentioned on http://api.jquery.com/category/selectors/
42
+ return value.replace(/([!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~])/g, "\\$1");
43
+ }
44
+
45
+ function getModelPrefix(fieldName) {
46
+ return fieldName.substr(0, fieldName.lastIndexOf(".") + 1);
47
+ }
48
+
49
+ function appendModelPrefix(value, prefix) {
50
+ if (value.indexOf("*.") === 0) {
51
+ value = value.replace("*.", prefix);
52
+ }
53
+ return value;
54
+ }
55
+
56
+ function onError(error, inputElement) { // 'this' is the form element
57
+ var container = $(this).find("[data-valmsg-for='" + escapeAttributeValue(inputElement[0].name) + "']"),
58
+ replaceAttrValue = container.attr("data-valmsg-replace"),
59
+ replace = replaceAttrValue ? JSON.parse(replaceAttrValue) !== false : null;
60
+
61
+ container.removeClass("field-validation-valid").addClass("field-validation-error");
62
+ error.data("unobtrusiveContainer", container);
63
+
64
+ if (replace) {
65
+ container.empty();
66
+ error.removeClass("input-validation-error").appendTo(container);
67
+ }
68
+ else {
69
+ error.hide();
70
+ }
71
+ }
72
+
73
+ function onErrors(event, validator) { // 'this' is the form element
74
+ var container = $(this).find("[data-valmsg-summary=true]"),
75
+ list = container.find("ul");
76
+
77
+ if (list && list.length && validator.errorList.length) {
78
+ list.empty();
79
+ container.addClass("validation-summary-errors").removeClass("validation-summary-valid");
80
+
81
+ $.each(validator.errorList, function () {
82
+ $("<li />").html(this.message).appendTo(list);
83
+ });
84
+ }
85
+ }
86
+
87
+ function onSuccess(error) { // 'this' is the form element
88
+ var container = error.data("unobtrusiveContainer");
89
+
90
+ if (container) {
91
+ var replaceAttrValue = container.attr("data-valmsg-replace"),
92
+ replace = replaceAttrValue ? JSON.parse(replaceAttrValue) : null;
93
+
94
+ container.addClass("field-validation-valid").removeClass("field-validation-error");
95
+ error.removeData("unobtrusiveContainer");
96
+
97
+ if (replace) {
98
+ container.empty();
99
+ }
100
+ }
101
+ }
102
+
103
+ function onReset(event) { // 'this' is the form element
104
+ var $form = $(this),
105
+ key = '__jquery_unobtrusive_validation_form_reset';
106
+ if ($form.data(key)) {
107
+ return;
108
+ }
109
+ // Set a flag that indicates we're currently resetting the form.
110
+ $form.data(key, true);
111
+ try {
112
+ $form.data("validator").resetForm();
113
+ } finally {
114
+ $form.removeData(key);
115
+ }
116
+
117
+ $form.find(".validation-summary-errors")
118
+ .addClass("validation-summary-valid")
119
+ .removeClass("validation-summary-errors");
120
+ $form.find(".field-validation-error")
121
+ .addClass("field-validation-valid")
122
+ .removeClass("field-validation-error")
123
+ .removeData("unobtrusiveContainer")
124
+ .find(">*") // If we were using valmsg-replace, get the underlying error
125
+ .removeData("unobtrusiveContainer");
126
+ }
127
+
128
+ function validationInfo(form) {
129
+ var $form = $(form),
130
+ result = $form.data(data_validation),
131
+ onResetProxy = onReset.bind(form),
132
+ defaultOptions = $jQval.unobtrusive.options || {},
133
+ execInContext = function (name, args) {
134
+ var func = defaultOptions[name];
135
+ func && typeof func === "function" && func.apply(form, args);
136
+ };
137
+
138
+ if (!result) {
139
+ result = {
140
+ options: { // options structure passed to jQuery Validate's validate() method
141
+ errorClass: defaultOptions.errorClass || "input-validation-error",
142
+ errorElement: defaultOptions.errorElement || "span",
143
+ errorPlacement: function () {
144
+ onError.apply(form, arguments);
145
+ execInContext("errorPlacement", arguments);
146
+ },
147
+ invalidHandler: function () {
148
+ onErrors.apply(form, arguments);
149
+ execInContext("invalidHandler", arguments);
150
+ },
151
+ messages: {},
152
+ rules: {},
153
+ success: function () {
154
+ onSuccess.apply(form, arguments);
155
+ execInContext("success", arguments);
156
+ }
157
+ },
158
+ attachValidation: function () {
159
+ $form
160
+ .off("reset." + data_validation)
161
+ .on("reset." + data_validation, onResetProxy)
162
+ .validate(this.options);
163
+ },
164
+ validate: function () { // a validation function that is called by unobtrusive Ajax
165
+ $form.validate();
166
+ return $form.valid();
167
+ }
168
+ };
169
+ $form.data(data_validation, result);
170
+ }
171
+
172
+ return result;
173
+ }
174
+
175
+ $jQval.unobtrusive = {
176
+ adapters: [],
177
+
178
+ parseElement: function (element, skipAttach) {
179
+ /// <summary>
180
+ /// Parses a single HTML element for unobtrusive validation attributes.
181
+ /// </summary>
182
+ /// <param name="element" domElement="true">The HTML element to be parsed.</param>
183
+ /// <param name="skipAttach" type="Boolean">[Optional] true to skip attaching the
184
+ /// validation to the form. If parsing just this single element, you should specify true.
185
+ /// If parsing several elements, you should specify false, and manually attach the validation
186
+ /// to the form when you are finished. The default is false.</param>
187
+ var $element = $(element),
188
+ form = $element.parents("form")[0],
189
+ valInfo, rules, messages;
190
+
191
+ if (!form) { // Cannot do client-side validation without a form
192
+ return;
193
+ }
194
+
195
+ valInfo = validationInfo(form);
196
+ valInfo.options.rules[element.name] = rules = {};
197
+ valInfo.options.messages[element.name] = messages = {};
198
+
199
+ $.each(this.adapters, function () {
200
+ var prefix = "data-val-" + this.name,
201
+ message = $element.attr(prefix),
202
+ paramValues = {};
203
+
204
+ if (message !== undefined) { // Compare against undefined, because an empty message is legal (and falsy)
205
+ prefix += "-";
206
+
207
+ $.each(this.params, function () {
208
+ paramValues[this] = $element.attr(prefix + this);
209
+ });
210
+
211
+ this.adapt({
212
+ element: element,
213
+ form: form,
214
+ message: message,
215
+ params: paramValues,
216
+ rules: rules,
217
+ messages: messages
218
+ });
219
+ }
220
+ });
221
+
222
+ $.extend(rules, { "__dummy__": true });
223
+
224
+ if (!skipAttach) {
225
+ valInfo.attachValidation();
226
+ }
227
+ },
228
+
229
+ parse: function (selector) {
230
+ /// <summary>
231
+ /// Parses all the HTML elements in the specified selector. It looks for input elements decorated
232
+ /// with the [data-val=true] attribute value and enables validation according to the data-val-*
233
+ /// attribute values.
234
+ /// </summary>
235
+ /// <param name="selector" type="String">Any valid jQuery selector.</param>
236
+
237
+ // $forms includes all forms in selector's DOM hierarchy (parent, children and self) that have at least one
238
+ // element with data-val=true
239
+ var $selector = $(selector),
240
+ $forms = $selector.parents()
241
+ .addBack()
242
+ .filter("form")
243
+ .add($selector.find("form"))
244
+ .has("[data-val=true]");
245
+
246
+ $selector.find("[data-val=true]").each(function () {
247
+ $jQval.unobtrusive.parseElement(this, true);
248
+ });
249
+
250
+ $forms.each(function () {
251
+ var info = validationInfo(this);
252
+ if (info) {
253
+ info.attachValidation();
254
+ }
255
+ });
256
+ }
257
+ };
258
+
259
+ adapters = $jQval.unobtrusive.adapters;
260
+
261
+ adapters.add = function (adapterName, params, fn) {
262
+ /// <summary>Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation.</summary>
263
+ /// <param name="adapterName" type="String">The name of the adapter to be added. This matches the name used
264
+ /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name).</param>
265
+ /// <param name="params" type="Array" optional="true">[Optional] An array of parameter names (strings) that will
266
+ /// be extracted from the data-val-nnnn-mmmm HTML attributes (where nnnn is the adapter name, and
267
+ /// mmmm is the parameter name).</param>
268
+ /// <param name="fn" type="Function">The function to call, which adapts the values from the HTML
269
+ /// attributes into jQuery Validate rules and/or messages.</param>
270
+ /// <returns type="jQuery.validator.unobtrusive.adapters" />
271
+ if (!fn) { // Called with no params, just a function
272
+ fn = params;
273
+ params = [];
274
+ }
275
+ this.push({ name: adapterName, params: params, adapt: fn });
276
+ return this;
277
+ };
278
+
279
+ adapters.addBool = function (adapterName, ruleName) {
280
+ /// <summary>Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where
281
+ /// the jQuery Validate validation rule has no parameter values.</summary>
282
+ /// <param name="adapterName" type="String">The name of the adapter to be added. This matches the name used
283
+ /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name).</param>
284
+ /// <param name="ruleName" type="String" optional="true">[Optional] The name of the jQuery Validate rule. If not provided, the value
285
+ /// of adapterName will be used instead.</param>
286
+ /// <returns type="jQuery.validator.unobtrusive.adapters" />
287
+ return this.add(adapterName, function (options) {
288
+ setValidationValues(options, ruleName || adapterName, true);
289
+ });
290
+ };
291
+
292
+ adapters.addMinMax = function (adapterName, minRuleName, maxRuleName, minMaxRuleName, minAttribute, maxAttribute) {
293
+ /// <summary>Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where
294
+ /// the jQuery Validate validation has three potential rules (one for min-only, one for max-only, and
295
+ /// one for min-and-max). The HTML parameters are expected to be named -min and -max.</summary>
296
+ /// <param name="adapterName" type="String">The name of the adapter to be added. This matches the name used
297
+ /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name).</param>
298
+ /// <param name="minRuleName" type="String">The name of the jQuery Validate rule to be used when you only
299
+ /// have a minimum value.</param>
300
+ /// <param name="maxRuleName" type="String">The name of the jQuery Validate rule to be used when you only
301
+ /// have a maximum value.</param>
302
+ /// <param name="minMaxRuleName" type="String">The name of the jQuery Validate rule to be used when you
303
+ /// have both a minimum and maximum value.</param>
304
+ /// <param name="minAttribute" type="String" optional="true">[Optional] The name of the HTML attribute that
305
+ /// contains the minimum value. The default is "min".</param>
306
+ /// <param name="maxAttribute" type="String" optional="true">[Optional] The name of the HTML attribute that
307
+ /// contains the maximum value. The default is "max".</param>
308
+ /// <returns type="jQuery.validator.unobtrusive.adapters" />
309
+ return this.add(adapterName, [minAttribute || "min", maxAttribute || "max"], function (options) {
310
+ var min = options.params.min,
311
+ max = options.params.max;
312
+
313
+ if (min && max) {
314
+ setValidationValues(options, minMaxRuleName, [min, max]);
315
+ }
316
+ else if (min) {
317
+ setValidationValues(options, minRuleName, min);
318
+ }
319
+ else if (max) {
320
+ setValidationValues(options, maxRuleName, max);
321
+ }
322
+ });
323
+ };
324
+
325
+ adapters.addSingleVal = function (adapterName, attribute, ruleName) {
326
+ /// <summary>Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where
327
+ /// the jQuery Validate validation rule has a single value.</summary>
328
+ /// <param name="adapterName" type="String">The name of the adapter to be added. This matches the name used
329
+ /// in the data-val-nnnn HTML attribute(where nnnn is the adapter name).</param>
330
+ /// <param name="attribute" type="String">[Optional] The name of the HTML attribute that contains the value.
331
+ /// The default is "val".</param>
332
+ /// <param name="ruleName" type="String" optional="true">[Optional] The name of the jQuery Validate rule. If not provided, the value
333
+ /// of adapterName will be used instead.</param>
334
+ /// <returns type="jQuery.validator.unobtrusive.adapters" />
335
+ return this.add(adapterName, [attribute || "val"], function (options) {
336
+ setValidationValues(options, ruleName || adapterName, options.params[attribute]);
337
+ });
338
+ };
339
+
340
+ $jQval.addMethod("__dummy__", function (value, element, params) {
341
+ return true;
342
+ });
343
+
344
+ $jQval.addMethod("regex", function (value, element, params) {
345
+ var match;
346
+ if (this.optional(element)) {
347
+ return true;
348
+ }
349
+
350
+ match = new RegExp(params).exec(value);
351
+ return (match && (match.index === 0) && (match[0].length === value.length));
352
+ });
353
+
354
+ $jQval.addMethod("nonalphamin", function (value, element, nonalphamin) {
355
+ var match;
356
+ if (nonalphamin) {
357
+ match = value.match(/\W/g);
358
+ match = match && match.length >= nonalphamin;
359
+ }
360
+ return match;
361
+ });
362
+
363
+ if ($jQval.methods.extension) {
364
+ adapters.addSingleVal("accept", "mimtype");
365
+ adapters.addSingleVal("extension", "extension");
366
+ } else {
367
+ // for backward compatibility, when the 'extension' validation method does not exist, such as with versions
368
+ // of JQuery Validation plugin prior to 1.10, we should use the 'accept' method for
369
+ // validating the extension, and ignore mime-type validations as they are not supported.
370
+ adapters.addSingleVal("extension", "extension", "accept");
371
+ }
372
+
373
+ adapters.addSingleVal("regex", "pattern");
374
+ adapters.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url");
375
+ adapters.addMinMax("length", "minlength", "maxlength", "rangelength").addMinMax("range", "min", "max", "range");
376
+ adapters.addMinMax("minlength", "minlength").addMinMax("maxlength", "minlength", "maxlength");
377
+ adapters.add("equalto", ["other"], function (options) {
378
+ var prefix = getModelPrefix(options.element.name),
379
+ other = options.params.other,
380
+ fullOtherName = appendModelPrefix(other, prefix),
381
+ element = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(fullOtherName) + "']")[0];
382
+
383
+ setValidationValues(options, "equalTo", element);
384
+ });
385
+ adapters.add("required", function (options) {
386
+ // jQuery Validate equates "required" with "mandatory" for checkbox elements
387
+ if (options.element.tagName.toUpperCase() !== "INPUT" || options.element.type.toUpperCase() !== "CHECKBOX") {
388
+ setValidationValues(options, "required", true);
389
+ }
390
+ });
391
+ adapters.add("remote", ["url", "type", "additionalfields"], function (options) {
392
+ var value = {
393
+ url: options.params.url,
394
+ type: options.params.type || "GET",
395
+ data: {}
396
+ },
397
+ prefix = getModelPrefix(options.element.name);
398
+
399
+ $.each(splitAndTrim(options.params.additionalfields || options.element.name), function (i, fieldName) {
400
+ var paramName = appendModelPrefix(fieldName, prefix);
401
+ value.data[paramName] = function () {
402
+ var field = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(paramName) + "']");
403
+ // For checkboxes and radio buttons, only pick up values from checked fields.
404
+ if (field.is(":checkbox")) {
405
+ return field.filter(":checked").val() || field.filter(":hidden").val() || '';
406
+ }
407
+ else if (field.is(":radio")) {
408
+ return field.filter(":checked").val() || '';
409
+ }
410
+ return field.val();
411
+ };
412
+ });
413
+
414
+ setValidationValues(options, "remote", value);
415
+ });
416
+ adapters.add("password", ["min", "nonalphamin", "regex"], function (options) {
417
+ if (options.params.min) {
418
+ setValidationValues(options, "minlength", options.params.min);
419
+ }
420
+ if (options.params.nonalphamin) {
421
+ setValidationValues(options, "nonalphamin", options.params.nonalphamin);
422
+ }
423
+ if (options.params.regex) {
424
+ setValidationValues(options, "regex", options.params.regex);
425
+ }
426
+ });
427
+ adapters.add("fileextensions", ["extensions"], function (options) {
428
+ setValidationValues(options, "extension", options.params.extensions);
429
+ });
430
+
431
+ $(function () {
432
+ $jQval.unobtrusive.parse(document);
433
+ });
434
+
435
+ return $jQval.unobtrusive;
436
+ }));