PageSourceSearch

https://praypub.org/FormWizard/js/Validation.js

js praypub.org collected 2026-09-25 02:31:12 UTC 2,934 bytes, 92 lines download raw bytes

1// Some of this script was borrowed from https://gist.github.com/meziantou/1755cd2d21c8a1d1d148
2
3// Set Element.matches() method to prefixed version if Element.matches() doesn't exist
4Element.prototype.matches || (Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector);
5// Polyfill Element.closest()
6Element.prototype.closest || (Element.prototype.closest = function (e) { var t = this; if (!document.documentElement.contains(t)) return null; do { if (t.matches(e)) return t; t = t.parentElement } while (null !== t); return null });
7
8// Check field for valadation on blur
9function validateOnChange(event) {
10	event = event || window.event;
11
12	var targetedControl = event.target,
13		vals,
14		valid = true;
15
16	Page_InvalidControlToBeFocused = null;
17
18	if (typeof (targetedControl.Validators) != 'undefined') {
19		vals = targetedControl.Validators;
20	} else {
21		if (targetedControl.tagName.toLowerCase() == 'label') {
22			targetedControl = document.getElementById(targetedControl.htmlFor);
23			vals = targetedControl.Validators;
24		}
25	}
26
27	if (vals) {
28		for (var i = 0; i < vals.length; i++) {
29			ValidatorValidate(vals[i], null, event);
30			if (!vals[i].isvalid) {
31				valid = false;
32			}
33		}
34	}
35
36	setInvalidOnRow(targetedControl, valid);
37}
38
39// Set validation on field
40function setInvalidOnRow(element, valid) {
41	var parent = element.parentNode;
42
43	if (parent.classList.contains('settingrow')) {
44		if (valid && parent.classList.contains(invalidInputRowClass)) {
45			parent.classList.remove(...invalidInputRowClass.split(' '));
46		} else if (!valid && !parent.classList.contains(invalidInputRowClass)) {
47			parent.classList.add(...invalidInputRowClass.split(' '));
48		}
49	} else {
50		setInvalidOnRow(parent, valid);
51	}
52}
53
54// Validate form fields on submit
55function extendedValidatorUpdateDisplay(obj) {
56	// Call the original method
57	if (typeof originalValidatorUpdateDisplay === 'function') {
58		originalValidatorUpdateDisplay(obj);
59	}
60
61	// Retrieves the state of the control (valid or invalid)
62	// and add or remove the has-error class
63	var control = document.getElementById(obj.controltovalidate);
64
65	if (control) {
66		if (control.Validators !== undefined) {
67			var isValid = true;
68
69			for (var i = 0; i < control.Validators.length; i += 1) {
70				if (!control.Validators[i].isvalid) {
71					isValid = false;
72					break;
73				}
74			}
75
76			if (isValid) {
77				control.closest('.settingrow').classList.remove('has-error');
78			} else {
79				control.closest('.settingrow').classList.add('has-error');
80			}
81		}
82	}
83}
84
85// Replaces the ValidatorUpdateDisplay method
86var originalValidatorUpdateDisplay = window.ValidatorUpdateDisplay;
87window.ValidatorUpdateDisplay = extendedValidatorUpdateDisplay;
88
89function DisableButton() {
90	document.getElementById(submitButtonId).disabled = true;
91}
92window.onbeforeunload = DisableButton;

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.