PageSourceSearch

https://forms.mediclinic.co.za/PatientBooking/Scripts/jquery-valid…y.validate.unobtrusive.js?ck=694ef52e063715

js mediclinic.co.za collected 2026-10-02 04:37:42 UTC 20,831 bytes, 460 lines download raw bytes

1/* NUGET: BEGIN LICENSE TEXT
2 *
3 * Microsoft grants you the right to use these script files for the sole
4 * purpose of either: (i) interacting through your browser with the Microsoft
5 * website or online service, subject to the applicable licensing or use
6 * terms; or (ii) using the files as included with a Microsoft product subject
7 * to that product's license terms. Microsoft reserves all other rights to the
8 * files not expressly granted by Microsoft, whether by implication, estoppel
9 * or otherwise. Insofar as a script file is dual licensed under GPL,
10 * Microsoft neither took the code under GPL nor distributes it thereunder but
11 * under the terms set out in this paragraph. All notices and licenses
12 * below are for informational purposes only.
13 *
14 * NUGET: END LICENSE TEXT */
15/*!
16** Unobtrusive validation support library for jQuery and jQuery Validate
17** Copyright (C) Microsoft Corporation. All rights reserved.
18*/
19
20/*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 */
21/*global document: false, jQuery: false */
22
23(function ($) {
24    var $jQval = $.validator,
25        adapters,
26        data_validation = "unobtrusiveValidation";
27
28    function setValidationValues(options, ruleName, value) {
29        options.rules[ruleName] = value;
30        if (options.message) {
31            options.messages[ruleName] = options.message;
32        }
33    }
34
35    function splitAndTrim(value) {
36        return value.replace(/^\s+|\s+$/g, "").split(/\s*,\s*/g);
37    }
38
39    function escapeAttributeValue(value) {
40        // As mentioned on http://api.jquery.com/category/selectors/
41        return value.replace(/([!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~])/g, "\\$1");
42    }
43
44    function getModelPrefix(fieldName) {
45        return fieldName.substr(0, fieldName.lastIndexOf(".") + 1);
46    }
47
48    function appendModelPrefix(value, prefix) {
49        if (value.indexOf("*.") === 0) {
50            value = value.replace("*.", prefix);
51        }
52        return value;
53    }
54
55    function onError(error, inputElement) {  // 'this' is the form element
56        var container = $(this).find("[data-valmsg-for='" + escapeAttributeValue(inputElement[0].name) + "']"),
57            replaceAttrValue = container.attr("data-valmsg-replace"),
58            replace = replaceAttrValue ? $.parseJSON(replaceAttrValue) !== false : null;
59
60        container.removeClass("field-validation-valid").addClass("field-validation-error");
61        error.data("unobtrusiveContainer", container);
62
63        if (replace) {
64            container.empty();
65            error.removeClass("input-validation-error").appendTo(container);
66
67            // Escalate validation class to Select2 UI element
68            escalateSelect2CssClass(inputElement, true);
69        } else {
70            error.hide();
71        }
72    }
73
74    function escalateSelect2CssClass(inputElement, canAdd) {
75        if (inputElement[0]) {
76            var tagName = inputElement[0].tagName;
77
78            if (tagName === "SELECT" || tagName === "OPTION") {
79
80                var field = $(inputElement[0]);
81                var cssClass = "input-validation-error-select2";
82
83                if (tagName === "OPTION")
84                    field = field.parent();
85
86                var select2Element = field.siblings('.select2-container');
87
88                if (select2Element.length > 0) {
89                    if (canAdd) {
90                        select2Element.addClass(cssClass);
91                    } else {
92                        select2Element.removeClass(cssClass);
93                    }
94                }
95            }
96        }
97    }
98
99    function onErrors(event, validator) {  // 'this' is the form element
100
101        var container = $(this).find("[data-valmsg-summary=true]"),
102            list = container.find("ul");
103
104        if (list && list.length && validator.errorList.length) {
105            list.empty();
106            container.addClass("validation-summary-errors").removeClass("val
106idation-summary-valid");
107
108            $.each(validator.errorList, function () {
109                $("<li />").html(this.message).appendTo(list);
110            });
111        }
112    }
113
114    function onSuccess(error, inputElement) {  // 'this' is the form element
115        var container = error.data("unobtrusiveContainer"),
116            replaceAttrValue = container.attr("data-valmsg-replace"),
117            replace = replaceAttrValue ? $.parseJSON(replaceAttrValue) : null;
118
119        if (container) {
120            container.addClass("field-validation-valid").removeClass("field-validation-error");
121            error.removeData("unobtrusiveContainer");
122
123            if (replace) {
124                container.empty();
125            }
126        }
127
128        // Remove validation class from Select2 UI element
129        escalateSelect2CssClass(inputElement, false);
130    }
131
132    function onReset(event) {  // 'this' is the form element
133        var $form = $(this),
134            key = '__jquery_unobtrusive_validation_form_reset';
135        if ($form.data(key)) {
136            return;
137        }
138        // Set a flag that indicates we're currently resetting the form.
139        $form.data(key, true);
140        try {
141            $form.data("validator").resetForm();
142        } finally {
143            $form.removeData(key);
144        }
145
146        $form.find(".validation-summary-errors")
147            .addClass("validation-summary-valid")
148            .removeClass("validation-summary-errors");
149        $form.find(".field-validation-error")
150            .addClass("field-validation-valid")
151            .removeClass("field-validation-error")
152            .removeData("unobtrusiveContainer")
153            .find(">*")  // If we were using valmsg-replace, get the underlying error
154            .removeData("unobtrusiveContainer");
155    }
156
157    function validationInfo(form) {
158        var $form = $(form),
159            result = $form.data(data_validation),
160            onResetProxy = $.proxy(onReset, form),
161            defaultOptions = $jQval.unobtrusive.options || {},
162            execInContext = function (name, args) {
163                var func = defaultOptions[name];
164                func && $.isFunction(func) && func.apply(form, args);
165            }
vendor: 14,354 bytes, lines 165-455
165
166
167        if (!result) {
168            result = {
169                options: {  // options structure passed to jQuery Validate's validate() method
170                    errorClass: defaultOptions.errorClass || "input-validation-error",
171                    errorElement: defaultOptions.errorElement || "span",
172                    errorPlacement: function () {
173                        onError.apply(form, arguments);
174                        execInContext("errorPlacement", arguments);
175                    },
176                    invalidHandler: function () {
177                        onErrors.apply(form, arguments);
178                        execInContext("invalidHandler", arguments);
179                    },
180                    messages: {},
181                    rules: {},
182                    success: function () {
183                        onSuccess.apply(form, arguments);
184                        execInContext("success", arguments);
185                    }
186                },
187                attachValidation: function () {
188                    $form
189                        .off("reset." + data_validation, onResetProxy)
190                        .on("reset." + data_validation, onResetProxy)
191                        .validate(this.options);
192                },
193                validate: function () {  // a validation function that is called by unobtrusive Ajax
194                    $form.validate();
195                    return $form.valid();
196                }
197            };
198            $form.data(data_validation, result);
199        }
200
201        return result;
202    }
203
204    $jQval.unobtrusive = {
205        adapters: [],
206
207        parseElement: function (element, skipAttach) {
208            /// <summary>
209            /// Parses a single HTML element for unobtrusive validation attributes.
210            /// </summary>
211            /// <param name="element" domElement="true">The HTML element to be parsed.</param>
212            /// <param name="skipAttach" type="Boolean">[Optional] true to skip attaching the
213            /// validation to the form. If parsing just this single element, you should specify true.
214            /// If parsing several elements, you should specify false, and manually attach the validation
215            /// to the form when you are finished. The default is false.</param>
216            var $element = $(element),
217                form = $element.parents("form")[0],
218                valInfo, rules, messages;
219
220            if (!form) {  // Cannot do client-side validation without a form
221                return;
222            }
223
224            valInfo = validationInfo(form);
225            valInfo.options.rules[element.name] = rules = {};
226            valInfo.options.messages[element.name] = messages = {};
227
228            $.each(this.adapters, function () {
229                var prefix = "data-val-" + this.name,
230                    message = $element.attr(prefix),
231                    paramValues = {};
232
233                if (message !== undefined) {  // Compare against undefined, because an empty message is legal (and falsy)
234                    prefix += "-";
235
236                    $.each(this.params, function () {
237                        paramValues[this] = $element.attr(prefix + this);
238                    });
239
240                    this.adapt({
241                        element: element,
242                        form: form,
243                        message: message,
244                        params: paramValues,
245                        rules: rules,
246                        messages: messages
247                    });
248                }
249            });
250
251            $.extend(rules, { "__dummy__": true });
252
253            if (!skipAttach) {
254                valInfo.attachValidation();
255            }
256        },
257
258        parse: function (selector) {
259            /// <summary>
260            /// Parses all the HTML elements in the specified selector. It looks for input elements decorated
261            /// with the [data-val=true] attribute value and enables validation according to the data-val-*
262            /// attribute values.
263            /// </summary>
264            /// <param name="selector" type="String">Any valid jQuery selector.</param>
265
266            // $forms includes all forms in selector's DOM hierarchy (parent, children and self) that have at least one
267            // element with data-val=true
268            var $selector = $(selector),
269                $forms = $selector.parents()
270                    .addBack()
271                    .filter("form")
272                    .add($selector.find("form"))
273                    .has("[data-val=true]");
274
275            $selector.find("[data-val=true]").each(function () {
276                $jQval.unobtrusive.parseElement(this, true);
277            });
278
279            $forms.each(function () {
280                var info = validationInfo(this);
281                if (info) {
282                    info.attachValidation();
283                }
284            });
285        }
286    };
287
288    adapters = $jQval.unobtrusive.adapters;
289
290    adapters.add = function (adapterName, params, fn) {
291        /// <summary>Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation.</summary>
292        /// <param name="adapterName" type="String">The name of the adapter to be added. This matches the name used
293        /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name).</param>
294        /// <param name="params" type="Array" optional="true">[Optional] An array of parameter names (strings) that will
295        /// be extracted from the data-val-nnnn-mmmm HTML attributes (where nnnn is the adapter name, and
296        /// mmmm is the parameter name).</param>
297        /// <param name="fn" type="Function">The function to call, which adapts the values from the HTML
298        /// attributes into jQuery Validate rules and/or messages.</param>
299        /// <returns type="jQuery.validator.unobtrusive.adapters" />
300        if (!fn) {  // Called with no params, just a function
301            fn = params;
302            params = [];
303        }
304        this.push({ name: adapterName, params: params, adapt: fn });
305        return this;
306    };
307
308    adapters.addBool = function (adapterName, ruleName) {
309        /// <summary>Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where
310        /// the jQuery Validate validation rule has no parameter values.</summary>
311        /// <param name="adapterName" type="String">The name of the adapter to be added. This matches the name used
312        /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name).</param>
313        /// <param name="ruleName" type="String" optional="true">[Optional] The name of the jQuery Validate rule. If not provided, the value
314        /// of adapterName will be used instead.</param>
315        /// <returns type="jQuery.validator.unobtrusive.adapters" />
316        return this.add(adapterName, function (options) {
317            setValidationValues(options, ruleName || adapterName, true);
318        });
319    };
320
321    adapters.addMinMax = function (adapterName, minRuleName, maxRuleName, minMaxRuleName, minAttribute, maxAttribute) {
322        /// <summary>Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where
323        /// the jQuery Validate validation has three potential rules (one for min-only, one for max-only, and
324        /// one for min-and-max). The HTML parameters are expected to be named -min and -max.</summary>
325        /// <param name="adapterName" type="String">The name of the adapter to be added. This matches the name used
326        /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name).</param>
327        /// <param name="minRuleName" type="String">The name of the jQuery Validate rule to be used when you only
328        /// have a minimum value.</param>
329        /// <param name="maxRuleName" type="String">The name of the jQuery Validate rule to be used when you only
330        /// have a maximum value.</param>
331        /// <param name="minMaxRuleName" type="String">The name of the jQuery Validate rule to be used when you
332        /// have both a minimum and maximum value.</param>
333        /// <param name="minAttribute" type="String" optional="true">[Optional] The name of the HTML attribute that
334        /// contains the minimum value. The default is "min".</param>
335        /// <param name="maxAttribute" type="String" optional="true">[Optional] The name of the HTML attribute that
336        /// contains the maximum value. The default is "max".</param>
337        /// <returns type="jQuery.validator.unobtrusive.adapters" />
338        return this.add(adapterName, [minAttribute || "min", maxAttribute || "max"], function (options) {
339            var min = options.params.min,
340                max = options.params.max;
341
342            if (min && max) {
343                setValidationValues(options, minMaxRuleName, [min, max]);
344            }
345            else if (min) {
346                setValidationValues(options, minRuleName, min);
347            }
348            else if (max) {
349                setValidationValues(options, maxRuleName, max);
350            }
351        });
352    };
353
354    adapters.addSingleVal = function (adapterName, attribute, ruleName) {
355        /// <summary>Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where
356        /// the jQuery Validate validation rule has a single value.</summary>
357        /// <param name="adapterName" type="String">The name of the adapter to be added. This matches the name used
358        /// in the data-val-nnnn HTML attribute(where nnnn is the adapter name).</param>
359        /// <param name="attribute" type="String">[Optional] The name of the HTML attribute that contains the value.
360        /// The default is "val".</param>
361        /// <param name="ruleName" type="String" optional="true">[Optional] The name of the jQuery Validate rule. If not provided, the value
362        /// of adapterName will be used instead.</param>
363        /// <returns type="jQuery.validator.unobtrusive.adapters" />
364        return this.add(adapterName, [attribute || "val"], function (options) {
365            setValidationValues(options, ruleName || adapterName, options.params[attribute]);
366        });
367    };
368
369    $jQval.addMethod("__dummy__", function (value, element, params) {
370        return true;
371    });
372
373    $jQval.addMethod("regex", function (value, element, params) {
374        var match;
375        if (this.optional(element)) {
376            return true;
377        }
378
379        match = new RegExp(params).exec(value);
380        return (match && (match.index === 0) && (match[0].length === value.length));
381    });
382
383    $jQval.addMethod("nonalphamin", function (value, element, nonalphamin) {
384        var match;
385        if (nonalphamin) {
386            match = value.match(/\W/g);
387            match = match && match.length >= nonalphamin;
388        }
389        return match;
390    });
391
392    if ($jQval.methods.extension) {
393        adapters.addSingleVal("accept", "mimtype");
394        adapters.addSingleVal("extension", "extension");
395    } else {
396        // for backward compatibility, when the 'extension' validation method does not exist, such as with versions
397        // of JQuery Validation plugin prior to 1.10, we should use the 'accept' method for
398        // validating the extension, and ignore mime-type validations as they are not supported.
399        adapters.addSingleVal("extension", "extension", "accept");
400    }
401
402    adapters.addSingleVal("regex", "pattern");
403    adapters.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url");
404    adapters.addMinMax("length", "minlength", "maxlength", "rangelength").addMinMax("range", "min", "max", "range");
405    adapters.addMinMax("minlength", "minlength").addMinMax("maxlength", "minlength", "maxlength");
406    adapters.add("equalto", ["other"], function (options) {
407        var prefix = getModelPrefix(options.element.name),
408            other = options.params.other,
409            fullOtherName = appendModelPrefix(other, prefix),
410            element = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(fullOtherName) + "']")[0];
411
412        setValidationValues(options, "equalTo", element);
413    });
414    adapters.add("required", function (options) {
415        // jQuery Validate equates "required" with "mandatory" for checkbox elements
416        if (options.element.tagName.toUpperCase() !== "INPUT" || options.element.type.toUpperCase() !== "CHECKBOX") {
417            setValidationValues(options, "required", true);
418        }
419    });
420    adapters.add("remote", ["url", "type", "additionalfields"], function (options) {
421        var value = {
422            url: options.params.url,
423            type: options.params.type || "GET",
424            data: {}
425        },
426            prefix = getModelPrefix(options.element.name);
427
428        $.each(splitAndTrim(options.params.additionalfields || options.element.name), function (i, fieldName) {
429            var paramName = appendModelPrefix(fieldName, prefix);
430            value.data[paramName] = function () {
431                var field = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(paramName) + "']");
432                // For checkboxes and radio buttons, only pick up values from checked fields.
433                if (field.is(":checkbox")) {
434                    return field.filter(":checked").val() || field.filter(":hidden").val() || '';
435                }
436                else if (field.is(":radio")) {
437                    return field.filter(":checked").val() || '';
438                }
439                return field.val();
440            };
441        });
442
443        setValidationValues(options, "remote", value);
444    });
445    adapters.add("password", ["min", "nonalphamin", "regex"], function (options) {
446        if (options.params.min) {
447            setValidationValues(options, "minlength", options.params.min);
448        }
449        if (options.params.nonalphamin) {
450            setValidationValues(options, "nonalphamin", options.params.nonalphamin);
451        }
452        if (options.params.regex) {
453            setValidationValues(options, "regex", options.params.regex);
454        }
455    });
456
457    $(function () {
458        $jQval.unobtrusive.parse(document);
459    });
460}(jQuery));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.